blob: 2f053349f8ae9d0f41fd469d9fb53be734bfb3c1 [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älkkif21c2ac2014-10-19 09:35:18 +030040#include <northbridge/amd/agesa/agesawrapper.h>
zbao2c08f6a2012-07-02 15:32:58 +080041
42#define MAX_NODE_NUMS (MAX_NODES * MAX_DIES)
43
zbao2c08f6a2012-07-02 15:32:58 +080044typedef struct dram_base_mask {
45 u32 base; //[47:27] at [28:8]
46 u32 mask; //[47:27] at [28:8] and enable at bit 0
47} dram_base_mask_t;
48
49static unsigned node_nums;
50static unsigned sblink;
51static device_t __f0_dev[MAX_NODE_NUMS];
52static device_t __f1_dev[MAX_NODE_NUMS];
53static device_t __f2_dev[MAX_NODE_NUMS];
54static device_t __f4_dev[MAX_NODE_NUMS];
55static unsigned fx_devs = 0;
56
57static dram_base_mask_t get_dram_base_mask(u32 nodeid)
58{
59 device_t dev;
60 dram_base_mask_t d;
61 dev = __f1_dev[0];
62 u32 temp;
63 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
64 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
65 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
66 d.mask |= temp<<21;
67 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
68 d.mask |= (temp & 1); // enable bit
69 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
70 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
71 d.base |= temp<<21;
72 return d;
73}
74
75static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg,
76 u32 io_min, u32 io_max)
77{
78 u32 i;
79 u32 tempreg;
80 /* io range allocation */
81 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn<<4) | ((io_max&0xf0)<<(12-4)); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020082 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +080083 pci_write_config32(__f1_dev[i], reg+4, tempreg);
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020084 tempreg = 3 /*| (3<<4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020085 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +080086 pci_write_config32(__f1_dev[i], reg, tempreg);
87}
88
89static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
90{
91 u32 i;
92 u32 tempreg;
93 /* io range allocation */
94 tempreg = (nodeid&0xf) | (linkn<<4) | (mmio_max&0xffffff00); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020095 for (i = 0; i < nodes; i++)
zbao2c08f6a2012-07-02 15:32:58 +080096 pci_write_config32(__f1_dev[i], reg+4, tempreg);
97 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020098 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +080099 pci_write_config32(__f1_dev[i], reg, tempreg);
100}
101
102static device_t get_node_pci(u32 nodeid, u32 fn)
103{
zbaod4627362012-07-23 19:49:40 +0800104#if MAX_NODE_NUMS + CONFIG_CDB >= 32
105 if ((CONFIG_CDB + nodeid) < 32) {
zbao2c08f6a2012-07-02 15:32:58 +0800106 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
107 } else {
108 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
109 }
110#else
111 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
112#endif
113}
114
115static void get_fx_devs(void)
116{
117 int i;
118 for (i = 0; i < MAX_NODE_NUMS; i++) {
119 __f0_dev[i] = get_node_pci(i, 0);
120 __f1_dev[i] = get_node_pci(i, 1);
121 __f2_dev[i] = get_node_pci(i, 2);
122 __f4_dev[i] = get_node_pci(i, 4);
123 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
124 fx_devs = i+1;
125 }
126 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
127 die("Cannot find 0:0x18.[0|1]\n");
128 }
129 printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs);
130}
131
132static u32 f1_read_config32(unsigned reg)
133{
134 if (fx_devs == 0)
135 get_fx_devs();
136 return pci_read_config32(__f1_dev[0], reg);
137}
138
139static void f1_write_config32(unsigned reg, u32 value)
140{
141 int i;
142 if (fx_devs == 0)
143 get_fx_devs();
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200144 for (i = 0; i < fx_devs; i++) {
zbao2c08f6a2012-07-02 15:32:58 +0800145 device_t dev;
146 dev = __f1_dev[i];
147 if (dev && dev->enabled) {
148 pci_write_config32(dev, reg, value);
149 }
150 }
151}
152
153static u32 amdfam15_nodeid(device_t dev)
154{
155#if MAX_NODE_NUMS == 64
156 unsigned busn;
157 busn = dev->bus->secondary;
158 if (busn != CONFIG_CBB) {
159 return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32;
160 } else {
161 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
162 }
163
164#else
165 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
166#endif
167}
168
169static void set_vga_enable_reg(u32 nodeid, u32 linkn)
170{
171 u32 val;
172
173 val = 1 | (nodeid<<4) | (linkn<<12);
174 /* it will routing
175 * (1)mmio 0xa0000:0xbffff
176 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
177 */
178 f1_write_config32(0xf4, val);
179
180}
181
182/**
183 * @return
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100184 * @retval 2 resoure does not exist, usable
185 * @retval 0 resource exists, not usable
zbao2c08f6a2012-07-02 15:32:58 +0800186 * @retval 1 resource exist, resource has been allocated before
187 */
188static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
189 unsigned goal_link)
190{
191 struct resource *res;
192 unsigned nodeid, link = 0;
193 int result;
194 res = 0;
195 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
196 device_t dev;
197 dev = __f0_dev[nodeid];
198 if (!dev)
199 continue;
200 for (link = 0; !res && (link < 8); link++) {
201 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
202 }
203 }
204 result = 2;
205 if (res) {
206 result = 0;
207 if ((goal_link == (link - 1)) &&
208 (goal_nodeid == (nodeid - 1)) &&
209 (res->flags <= 1)) {
210 result = 1;
211 }
212 }
213 return result;
214}
215
216static struct resource *amdfam15_find_iopair(device_t dev, unsigned nodeid, unsigned link)
217{
218 struct resource *resource;
219 u32 free_reg, reg;
220 resource = 0;
221 free_reg = 0;
222 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
223 int result;
224 result = reg_useable(reg, dev, nodeid, link);
225 if (result == 1) {
226 /* I have been allocated this one */
227 break;
228 }
229 else if (result > 1) {
230 /* I have a free register pair */
231 free_reg = reg;
232 }
233 }
234 if (reg > 0xd8) {
235 reg = free_reg; // if no free, the free_reg still be 0
236 }
237
238 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
239
240 return resource;
241}
242
243static struct resource *amdfam15_find_mempair(device_t dev, u32 nodeid, u32 link)
244{
245 struct resource *resource;
246 u32 free_reg, reg;
247 resource = 0;
248 free_reg = 0;
249 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
250 int result;
251 result = reg_useable(reg, dev, nodeid, link);
252 if (result == 1) {
253 /* I have been allocated this one */
254 break;
255 }
256 else if (result > 1) {
257 /* I have a free register pair */
258 free_reg = reg;
259 }
260 }
261 if (reg > 0xb8) {
262 reg = free_reg;
263 }
264
265 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
266 return resource;
267}
268
269static void amdfam15_link_read_bases(device_t dev, u32 nodeid, u32 link)
270{
271 struct resource *resource;
272
273 /* Initialize the io space constraints on the current bus */
274 resource = amdfam15_find_iopair(dev, nodeid, link);
275 if (resource) {
276 u32 align;
277 align = log2(HT_IO_HOST_ALIGN);
278 resource->base = 0;
279 resource->size = 0;
280 resource->align = align;
281 resource->gran = align;
282 resource->limit = 0xffffUL;
283 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
284 }
285
286 /* Initialize the prefetchable memory constraints on the current bus */
287 resource = amdfam15_find_mempair(dev, nodeid, link);
288 if (resource) {
289 resource->base = 0;
290 resource->size = 0;
291 resource->align = log2(HT_MEM_HOST_ALIGN);
292 resource->gran = log2(HT_MEM_HOST_ALIGN);
293 resource->limit = 0xffffffffffULL;
294 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
295 resource->flags |= IORESOURCE_BRIDGE;
296 }
297
298 /* Initialize the memory constraints on the current bus */
299 resource = amdfam15_find_mempair(dev, nodeid, link);
300 if (resource) {
301 resource->base = 0;
302 resource->size = 0;
303 resource->align = log2(HT_MEM_HOST_ALIGN);
304 resource->gran = log2(HT_MEM_HOST_ALIGN);
305 resource->limit = 0xffffffffffULL;
306 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
307 }
308
309}
310
Steven Sherkf4340582013-01-29 16:13:35 -0700311static void nb_read_resources(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800312{
313 u32 nodeid;
314 struct bus *link;
315
316 nodeid = amdfam15_nodeid(dev);
317 for (link = dev->link_list; link; link = link->next) {
318 if (link->children) {
319 amdfam15_link_read_bases(dev, nodeid, link->link_num);
320 }
321 }
Steven Sherk1cbabb02013-02-01 09:22:35 -0700322
323 /*
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800324 * This MMCONF resource must be reserved in the PCI domain.
Steven Sherk1cbabb02013-02-01 09:22:35 -0700325 * It is not honored by the coreboot resource allocator if it is in
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800326 * the CPU_CLUSTER.
Steven Sherk1cbabb02013-02-01 09:22:35 -0700327 */
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200328 mmconf_resource(dev, 0xc0010058);
zbao2c08f6a2012-07-02 15:32:58 +0800329}
330
331static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
332{
333 resource_t rbase, rend;
334 unsigned reg, link_num;
335 char buf[50];
336
337 /* Make certain the resource has actually been set */
338 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
339 return;
340 }
341
342 /* If I have already stored this resource don't worry about it */
343 if (resource->flags & IORESOURCE_STORED) {
344 return;
345 }
346
347 /* Only handle PCI memory and IO resources */
348 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
349 return;
350
351 /* Ensure I am actually looking at a resource of function 1 */
352 if ((resource->index & 0xffff) < 0x1000) {
353 return;
354 }
355 /* Get the base address */
356 rbase = resource->base;
357
358 /* Get the limit (rounded up) */
359 rend = resource_end(resource);
360
361 /* Get the register and link */
362 reg = resource->index & 0xfff; // 4k
363 link_num = IOINDEX_LINK(resource->index);
364
365 if (resource->flags & IORESOURCE_IO) {
366 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
367 }
368 else if (resource->flags & IORESOURCE_MEM) {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100369 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 +0800370 }
371 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200372 snprintf(buf, sizeof(buf), " <node %x link %x>",
zbao2c08f6a2012-07-02 15:32:58 +0800373 nodeid, link_num);
374 report_resource_stored(dev, resource, buf);
375}
376
377/**
378 * I tried to reuse the resource allocation code in set_resource()
379 * but it is too difficult to deal with the resource allocation magic.
380 */
381
382static void create_vga_resource(device_t dev, unsigned nodeid)
383{
384 struct bus *link;
385
386 /* find out which link the VGA card is connected,
387 * we only deal with the 'first' vga card */
388 for (link = dev->link_list; link; link = link->next) {
389 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
zbaod59d6242012-07-23 19:41:03 +0800390#if CONFIG_MULTIPLE_VGA_ADAPTERS
zbao2c08f6a2012-07-02 15:32:58 +0800391 extern device_t vga_pri; // the primary vga device, defined in device.c
392 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
393 link->secondary,link->subordinate);
394 /* We need to make sure the vga_pri is under the link */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200395 if ((vga_pri->bus->secondary >= link->secondary) &&
396 (vga_pri->bus->secondary <= link->subordinate))
zbao2c08f6a2012-07-02 15:32:58 +0800397#endif
398 break;
399 }
400 }
401
402 /* no VGA card installed */
403 if (link == NULL)
404 return;
405
406 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
407 set_vga_enable_reg(nodeid, sblink);
408}
409
Steven Sherkf4340582013-01-29 16:13:35 -0700410static void nb_set_resources(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800411{
412 unsigned nodeid;
413 struct bus *bus;
414 struct resource *res;
415
416 /* Find the nodeid */
417 nodeid = amdfam15_nodeid(dev);
418
419 create_vga_resource(dev, nodeid); //TODO: do we need this?
420
421 /* Set each resource we have found */
422 for (res = dev->resource_list; res; res = res->next) {
423 set_resource(dev, res, nodeid);
424 }
425
426 for (bus = dev->link_list; bus; bus = bus->next) {
427 if (bus->children) {
428 assign_resources(bus);
429 }
430 }
431}
432
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100433
434static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200435{
436 void *addr, *current;
437
438 /* Skip the HEST header. */
439 current = (void *)(hest + 1);
440
441 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
442 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700443 current += acpi_create_hest_error_source(hest, current, 0,
444 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200445
446 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
447 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700448 current += acpi_create_hest_error_source(hest, current, 1,
449 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200450
451 return (unsigned long)current;
452}
453
Alexander Couzens5eea4582015-04-12 22:18:55 +0200454static void northbridge_fill_ssdt_generator(device_t device)
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200455{
456 msr_t msr;
457 char pscope[] = "\\_SB.PCI0";
458
459 acpigen_write_scope(pscope);
460 msr = rdmsr(TOP_MEM);
461 acpigen_write_name_dword("TOM1", msr.lo);
462 msr = rdmsr(TOP_MEM2);
463 /*
464 * Since XP only implements parts of ACPI 2.0, we can't use a qword
465 * here.
466 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
467 * slide 22ff.
468 * Shift value right by 20 bit to make it fit into 32bit,
469 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
470 */
471 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
472 acpigen_pop_len();
473}
474
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200475static unsigned long agesa_write_acpi_tables(device_t device,
476 unsigned long current,
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200477 acpi_rsdp_t *rsdp)
478{
479 acpi_srat_t *srat;
480 acpi_slit_t *slit;
481 acpi_header_t *ssdt;
482 acpi_header_t *alib;
483 acpi_header_t *ivrs;
484 acpi_hest_t *hest;
485
486 /* HEST */
487 current = ALIGN(current, 8);
488 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100489 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200490 acpi_add_table(rsdp, (void *)current);
491 current += ((acpi_header_t *)current)->length;
492
493 current = ALIGN(current, 8);
494 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
495 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
496 if (ivrs != NULL) {
497 memcpy((void *)current, ivrs, ivrs->length);
498 ivrs = (acpi_header_t *) current;
499 current += ivrs->length;
500 acpi_add_table(rsdp, ivrs);
501 } else {
502 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
503 }
504
505 /* SRAT */
506 current = ALIGN(current, 8);
507 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
508 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
509 if (srat != NULL) {
510 memcpy((void *)current, srat, srat->header.length);
511 srat = (acpi_srat_t *) current;
512 current += srat->header.length;
513 acpi_add_table(rsdp, srat);
514 } else {
515 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
516 }
517
518 /* SLIT */
519 current = ALIGN(current, 8);
520 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
521 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
522 if (slit != NULL) {
523 memcpy((void *)current, slit, slit->header.length);
524 slit = (acpi_slit_t *) current;
525 current += slit->header.length;
526 acpi_add_table(rsdp, slit);
527 } else {
528 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
529 }
530
531 /* ALIB */
532 current = ALIGN(current, 16);
533 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
534 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
535 if (alib != NULL) {
536 memcpy((void *)current, alib, alib->length);
537 alib = (acpi_header_t *) current;
538 current += alib->length;
539 acpi_add_table(rsdp, (void *)alib);
540 }
541 else {
542 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
543 }
544
545 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
546 /* SSDT */
547 current = ALIGN(current, 16);
548 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
549 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
550 if (ssdt != NULL) {
551 memcpy((void *)current, ssdt, ssdt->length);
552 ssdt = (acpi_header_t *) current;
553 current += ssdt->length;
554 }
555 else {
556 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
557 }
558 acpi_add_table(rsdp,ssdt);
559
560 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
561
562 return current;
563}
564
565
zbao2c08f6a2012-07-02 15:32:58 +0800566static struct device_operations northbridge_operations = {
Steven Sherkf4340582013-01-29 16:13:35 -0700567 .read_resources = nb_read_resources,
568 .set_resources = nb_set_resources,
zbao2c08f6a2012-07-02 15:32:58 +0800569 .enable_resources = pci_dev_enable_resources,
Edward O'Callaghand994ef12014-11-21 02:22:33 +1100570 .init = DEVICE_NOOP,
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200571 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
572 .write_acpi_tables = agesa_write_acpi_tables,
zbao2c08f6a2012-07-02 15:32:58 +0800573 .enable = 0,
574 .ops_pci = 0,
575};
576
577static const struct pci_driver family15_northbridge __pci_driver = {
578 .ops = &northbridge_operations,
579 .vendor = PCI_VENDOR_ID_AMD,
Marshall Dawson463f46e2016-10-14 20:46:08 -0600580 .device = PCI_DEVICE_ID_AMD_15H_MODEL_101F_NB_HT,
zbao2c08f6a2012-07-02 15:32:58 +0800581};
582
583static const struct pci_driver family10_northbridge __pci_driver = {
584 .ops = &northbridge_operations,
585 .vendor = PCI_VENDOR_ID_AMD,
586 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
587};
588
589struct chip_operations northbridge_amd_agesa_family15tn_ops = {
590 CHIP_NAME("AMD FAM15 Northbridge")
591 .enable_dev = 0,
592};
593
594static void domain_read_resources(device_t dev)
595{
596 unsigned reg;
597
598 /* Find the already assigned resource pairs */
599 get_fx_devs();
600 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
601 u32 base, limit;
602 base = f1_read_config32(reg);
603 limit = f1_read_config32(reg + 0x04);
604 /* Is this register allocated? */
605 if ((base & 3) != 0) {
606 unsigned nodeid, reg_link;
607 device_t reg_dev;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200608 if (reg < 0xc0) { // mmio
zbao2c08f6a2012-07-02 15:32:58 +0800609 nodeid = (limit & 0xf) + (base&0x30);
610 } else { // io
611 nodeid = (limit & 0xf) + ((base>>4)&0x30);
612 }
613 reg_link = (limit >> 4) & 7;
614 reg_dev = __f0_dev[nodeid];
615 if (reg_dev) {
616 /* Reserve the resource */
617 struct resource *res;
618 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
619 if (res) {
620 res->flags = 1;
621 }
622 }
623 }
624 }
625 /* FIXME: do we need to check extend conf space?
626 I don't believe that much preset value */
627
zbao2c08f6a2012-07-02 15:32:58 +0800628 pci_domain_read_resources(dev);
zbao2c08f6a2012-07-02 15:32:58 +0800629}
630
zbao2c08f6a2012-07-02 15:32:58 +0800631static void domain_enable_resources(device_t dev)
632{
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +0300633 if (acpi_is_wakeup_s3())
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300634 agesawrapper_fchs3laterestore();
zbao2c08f6a2012-07-02 15:32:58 +0800635
636 /* Must be called after PCI enumeration and resource allocation */
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300637 if (!acpi_is_wakeup_s3()) {
638 /* Enable MMIO on AMD CPU Address Map Controller */
Kyösti Mälkki48518f02014-11-25 14:20:57 +0200639 amd_initcpuio();
zbao2c08f6a2012-07-02 15:32:58 +0800640
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300641 agesawrapper_amdinitmid();
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300642 }
Mike Loptiene133aab2013-01-30 16:00:43 -0700643 printk(BIOS_DEBUG, " ader - leaving %s.\n", __func__);
zbao2c08f6a2012-07-02 15:32:58 +0800644}
645
646#if CONFIG_HW_MEM_HOLE_SIZEK != 0
647struct hw_mem_hole_info {
648 unsigned hole_startk;
649 int node_id;
650};
651static struct hw_mem_hole_info get_hw_mem_hole_info(void)
652{
653 struct hw_mem_hole_info mem_hole;
654 int i;
655 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
656 mem_hole.node_id = -1;
657 for (i = 0; i < node_nums; i++) {
658 dram_base_mask_t d;
659 u32 hole;
660 d = get_dram_base_mask(i);
661 if (!(d.mask & 1)) continue; // no memory on this node
662 hole = pci_read_config32(__f1_dev[i], 0xf0);
663 if (hole & 1) { // we find the hole
664 mem_hole.hole_startk = (hole & (0xff<<24)) >> 10;
665 mem_hole.node_id = i; // record the node No with hole
666 break; // only one hole
667 }
668 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300669
670 /* We need to double check if there is special set on base reg and limit reg
671 * are not continuous instead of hole, it will find out its hole_startk.
672 */
zbao2c08f6a2012-07-02 15:32:58 +0800673 if (mem_hole.node_id == -1) {
674 resource_t limitk_pri = 0;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200675 for (i = 0; i < node_nums; i++) {
zbao2c08f6a2012-07-02 15:32:58 +0800676 dram_base_mask_t d;
677 resource_t base_k, limit_k;
678 d = get_dram_base_mask(i);
679 if (!(d.base & 1)) continue;
680 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
681 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
682 if (limitk_pri != base_k) { // we find the hole
683 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
684 mem_hole.node_id = i;
685 break; //only one hole
686 }
zbao15dc3cc2012-08-03 15:56:21 +0800687 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800688 limitk_pri = limit_k;
689 }
690 }
691 return mem_hole;
692}
693#endif
694
zbao405cfe22012-07-23 19:44:29 +0800695#define ONE_MB_SHIFT 20
zbao6db7f342012-07-19 16:38:12 +0800696
Kyösti Mälkki6b5eb1c2012-07-19 19:26:43 +0300697static void setup_uma_memory(void)
zbao6db7f342012-07-19 16:38:12 +0800698{
699#if CONFIG_GFXUMA
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300700 uint32_t topmem = (uint32_t) bsp_topmem();
zbao6db7f342012-07-19 16:38:12 +0800701 uint32_t sys_mem;
702
zbao6db7f342012-07-19 16:38:12 +0800703 /* refer to UMA Size Consideration in Family15h BKDG. */
704 /* Please reference MemNGetUmaSizeOR () */
705 /*
706 * Total system memory UMASize
707 * >= 2G 512M
708 * >=1G 256M
709 * <1G 64M
710 */
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300711 sys_mem = topmem + (16 << ONE_MB_SHIFT); // Ignore 16MB allocated for C6 when finding UMA size
712 if ((bsp_topmem2()>>32) || (sys_mem >= 2048 << ONE_MB_SHIFT)) {
zbao405cfe22012-07-23 19:44:29 +0800713 uma_memory_size = 512 << ONE_MB_SHIFT;
714 } else if (sys_mem >= 1024 << ONE_MB_SHIFT) {
715 uma_memory_size = 256 << ONE_MB_SHIFT;
zbao6db7f342012-07-19 16:38:12 +0800716 } else {
zbao405cfe22012-07-23 19:44:29 +0800717 uma_memory_size = 64 << ONE_MB_SHIFT;
zbao6db7f342012-07-19 16:38:12 +0800718 }
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300719 uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */
zbao6db7f342012-07-19 16:38:12 +0800720
721 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
722 __func__, uma_memory_size, uma_memory_base);
zbao6db7f342012-07-19 16:38:12 +0800723#endif
724}
725
726
zbao2c08f6a2012-07-02 15:32:58 +0800727static void domain_set_resources(device_t dev)
728{
zbao2c08f6a2012-07-02 15:32:58 +0800729 unsigned long mmio_basek;
730 u32 pci_tolm;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300731 u64 ramtop = 0;
zbao2c08f6a2012-07-02 15:32:58 +0800732 int i, idx;
733 struct bus *link;
734#if CONFIG_HW_MEM_HOLE_SIZEK != 0
735 struct hw_mem_hole_info mem_hole;
736 u32 reset_memhole = 1;
737#endif
738
zbao2c08f6a2012-07-02 15:32:58 +0800739 pci_tolm = 0xffffffffUL;
740 for (link = dev->link_list; link; link = link->next) {
741 pci_tolm = find_pci_tolm(link);
742 }
743
744 // FIXME handle interleaved nodes. If you fix this here, please fix
745 // amdk8, too.
746 mmio_basek = pci_tolm >> 10;
747 /* Round mmio_basek to something the processor can support */
748 mmio_basek &= ~((1 << 6) -1);
749
750 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
751 // MMIO hole. If you fix this here, please fix amdk8, too.
752 /* Round the mmio hole to 64M */
753 mmio_basek &= ~((64*1024) - 1);
754
755#if CONFIG_HW_MEM_HOLE_SIZEK != 0
756 /* if the hw mem hole is already set in raminit stage, here we will compare
757 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
758 * use hole_basek as mmio_basek and we don't need to reset hole.
759 * otherwise We reset the hole to the mmio_basek
760 */
761
762 mem_hole = get_hw_mem_hole_info();
763
764 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
765 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
766 mmio_basek = mem_hole.hole_startk;
767 reset_memhole = 0;
768 }
769#endif
770
771 idx = 0x10;
772 for (i = 0; i < node_nums; i++) {
773 dram_base_mask_t d;
774 resource_t basek, limitk, sizek; // 4 1T
775
776 d = get_dram_base_mask(i);
777
778 if (!(d.mask & 1)) continue;
779 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100780 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800781
782 sizek = limitk - basek;
783
784 /* see if we need a hole from 0xa0000 to 0xbffff */
785 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
786 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
787 idx += 0x10;
788 basek = (8*64)+(16*16);
789 sizek = limitk - ((8*64)+(16*16));
790
791 }
792
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300793 /* split the region to accommodate pci memory space */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200794 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
zbao2c08f6a2012-07-02 15:32:58 +0800795 if (basek <= mmio_basek) {
796 unsigned pre_sizek;
797 pre_sizek = mmio_basek - basek;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200798 if (pre_sizek > 0) {
zbao2c08f6a2012-07-02 15:32:58 +0800799 ram_resource(dev, (idx | i), basek, pre_sizek);
800 idx += 0x10;
801 sizek -= pre_sizek;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300802 if (!ramtop)
803 ramtop = mmio_basek * 1024;
zbao2c08f6a2012-07-02 15:32:58 +0800804 }
805 basek = mmio_basek;
806 }
807 if ((basek + sizek) <= 4*1024*1024) {
808 sizek = 0;
809 }
810 else {
Siyuan Wang29840e22013-06-04 19:56:22 +0800811 uint64_t topmem2 = bsp_topmem2();
zbao2c08f6a2012-07-02 15:32:58 +0800812 basek = 4*1024*1024;
Siyuan Wang29840e22013-06-04 19:56:22 +0800813 sizek = topmem2/1024 - basek;
zbao2c08f6a2012-07-02 15:32:58 +0800814 }
815 }
816
zbao2c08f6a2012-07-02 15:32:58 +0800817 ram_resource(dev, (idx | i), basek, sizek);
818 idx += 0x10;
zbao2c08f6a2012-07-02 15:32:58 +0800819 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
820 i, mmio_basek, basek, limitk);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300821 if (!ramtop)
822 ramtop = limitk * 1024;
zbao2c08f6a2012-07-02 15:32:58 +0800823 }
824
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300825#if CONFIG_GFXUMA
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300826 set_top_of_ram(uma_memory_base);
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300827 uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300828#else
829 set_top_of_ram(ramtop);
zbao2c08f6a2012-07-02 15:32:58 +0800830#endif
831
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200832 for (link = dev->link_list; link; link = link->next) {
zbao2c08f6a2012-07-02 15:32:58 +0800833 if (link->children) {
834 assign_resources(link);
835 }
836 }
837}
838
839static struct device_operations pci_domain_ops = {
840 .read_resources = domain_read_resources,
841 .set_resources = domain_set_resources,
842 .enable_resources = domain_enable_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100843 .init = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +0800844 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki872c9222013-07-03 09:44:28 +0300845 .ops_pci_bus = pci_bus_default_ops,
zbao2c08f6a2012-07-02 15:32:58 +0800846};
847
848static void sysconf_init(device_t dev) // first node
849{
850 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
851 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
852}
853
854static void add_more_links(device_t dev, unsigned total_links)
855{
856 struct bus *link, *last = NULL;
857 int link_num;
858
859 for (link = dev->link_list; link; link = link->next)
860 last = link;
861
862 if (last) {
863 int links = total_links - last->link_num;
864 link_num = last->link_num;
865 if (links > 0) {
866 link = malloc(links*sizeof(*link));
867 if (!link)
868 die("Couldn't allocate more links!\n");
869 memset(link, 0, links*sizeof(*link));
870 last->next = link;
871 }
872 }
873 else {
874 link_num = -1;
875 link = malloc(total_links*sizeof(*link));
876 memset(link, 0, total_links*sizeof(*link));
877 dev->link_list = link;
878 }
879
880 for (link_num = link_num + 1; link_num < total_links; link_num++) {
881 link->link_num = link_num;
882 link->dev = dev;
883 link->next = link + 1;
884 last = link;
885 link = link->next;
886 }
887 last->next = NULL;
888}
889
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200890static void cpu_bus_scan(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800891{
892 struct bus *cpu_bus;
893 device_t dev_mc;
894#if CONFIG_CBB
895 device_t pci_domain;
896#endif
897 int i,j;
898 int coreid_bits;
899 int core_max = 0;
900 unsigned ApicIdCoreIdSize;
901 unsigned core_nums;
902 int siblings = 0;
903 unsigned int family;
904
905#if CONFIG_CBB
906 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
907 if (dev_mc && dev_mc->bus) {
908 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
909 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800910 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800911 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
912 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
913 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
914 } else {
915 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
916 }
917 printk(BIOS_DEBUG, "\n");
918 }
919 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
920 if (!dev_mc) {
921 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
922 if (dev_mc && dev_mc->bus) {
923 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
924 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800925 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800926 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
927 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
928 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
929 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
930 while (dev_mc) {
931 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
932 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
933 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
934 dev_mc = dev_mc->sibling;
935 }
936 }
937 }
938 }
939 }
940#endif
941 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
942 if (!dev_mc) {
943 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
944 die("");
945 }
946 sysconf_init(dev_mc);
947#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200948 if (node_nums > 32) { // need to put node 32 to node 63 to bus 0xfe
zbao2c08f6a2012-07-02 15:32:58 +0800949 if (pci_domain->link_list && !pci_domain->link_list->next) {
950 struct bus *new_link = new_link(pci_domain);
951 pci_domain->link_list->next = new_link;
952 new_link->link_num = 1;
953 new_link->dev = pci_domain;
954 new_link->children = 0;
955 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
956 }
957 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
958 }
959#endif
960
961 /* Get Max Number of cores(MNC) */
962 coreid_bits = (cpuid_ecx(AMD_CPUID_ASIZE_PCCOUNT) & 0x0000F000) >> 12;
963 core_max = 1 << (coreid_bits & 0x000F); //mnc
964
965 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
966 if (ApicIdCoreIdSize) {
967 core_nums = (1 << ApicIdCoreIdSize) - 1;
968 } else {
969 core_nums = 3; //quad core
970 }
971
972 /* Find which cpus are present */
973 cpu_bus = dev->link_list;
974 for (i = 0; i < node_nums; i++) {
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300975 device_t cdb_dev;
zbao2c08f6a2012-07-02 15:32:58 +0800976 unsigned busn, devn;
977 struct bus *pbus;
978
979 busn = CONFIG_CBB;
980 devn = CONFIG_CDB + i;
981 pbus = dev_mc->bus;
982#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
983 if (i >= 32) {
984 busn--;
985 devn -= 32;
986 pbus = pci_domain->link_list->next;
987 }
988#endif
989
990 /* Find the cpu's pci device */
991 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
992 if (!cdb_dev) {
993 /* If I am probing things in a weird order
994 * ensure all of the cpu's pci devices are found.
995 */
996 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200997 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
zbao2c08f6a2012-07-02 15:32:58 +0800998 cdb_dev = pci_probe_dev(NULL, pbus,
999 PCI_DEVFN(devn, fn));
1000 }
1001 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
1002 } else {
1003 /* Ok, We need to set the links for that device.
1004 * otherwise the device under it will not be scanned
1005 */
Kyösti Mälkki2a2d6132015-02-04 13:25:37 +02001006 add_more_links(cdb_dev, 4);
zbao2c08f6a2012-07-02 15:32:58 +08001007 }
1008
1009 family = cpuid_eax(1);
1010 family = (family >> 20) & 0xFF;
1011 if (family == 1) { //f10
1012 u32 dword;
1013 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
1014 dword = pci_read_config32(cdb_dev, 0xe8);
1015 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
1016 } else if (family == 6) {//f15
1017 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
1018 if (cdb_dev && cdb_dev->enabled) {
1019 siblings = pci_read_config32(cdb_dev, 0x84);
1020 siblings &= 0xFF;
1021 }
1022 } else {
1023 siblings = 0; //default one core
1024 }
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +03001025 int enable_node = cdb_dev && cdb_dev->enabled;
zbao2c08f6a2012-07-02 15:32:58 +08001026 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
1027 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
1028
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +02001029 for (j = 0; j <= siblings; j++) {
zbao2c08f6a2012-07-02 15:32:58 +08001030 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
1031 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
1032 u32 lapicid_start = 0;
1033
zbao2c08f6a2012-07-02 15:32:58 +08001034 /*
1035 * APIC ID calucation is tightly coupled with AGESA v5 code.
1036 * This calculation MUST match the assignment calculation done
1037 * in LocalApicInitializationAtEarly() function.
1038 * And reference GetLocalApicIdForCore()
1039 *
1040 * Apply apic enumeration rules
1041 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1042 * put the local-APICs at m..z
1043 *
1044 * This is needed because many IO-APIC devices only have 4 bits
1045 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001046 */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001047
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001048 u8 plat_num_io_apics = 3; /* FIXME */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001049
1050 if ((node_nums * core_max) + plat_num_io_apics >= 0x10) {
1051 lapicid_start = (plat_num_io_apics - 1) / core_max;
zbao2c08f6a2012-07-02 15:32:58 +08001052 lapicid_start = (lapicid_start + 1) * core_max;
1053 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
1054 }
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001055 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
zbao2c08f6a2012-07-02 15:32:58 +08001056 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001057 i, j, apic_id);
zbao2c08f6a2012-07-02 15:32:58 +08001058
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001059 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1060 if (cpu)
1061 amd_cpu_topology(cpu, i, j);
zbao2c08f6a2012-07-02 15:32:58 +08001062 } //j
1063 }
zbao2c08f6a2012-07-02 15:32:58 +08001064}
1065
1066static void cpu_bus_init(device_t dev)
1067{
1068 initialize_cpus(dev->link_list);
1069}
1070
zbao2c08f6a2012-07-02 15:32:58 +08001071static struct device_operations cpu_bus_ops = {
Edward O'Callaghan2837ab22014-11-06 08:57:40 +11001072 .read_resources = DEVICE_NOOP,
1073 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001074 .enable_resources = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +08001075 .init = cpu_bus_init,
1076 .scan_bus = cpu_bus_scan,
1077};
1078
1079static void root_complex_enable_dev(struct device *dev)
1080{
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001081 static int done = 0;
1082
1083 /* Do not delay UMA setup, as a device on the PCI bus may evaluate
1084 the global uma_memory variables already in its enable function. */
1085 if (!done) {
1086 setup_bsp_ramtop();
1087 setup_uma_memory();
1088 done = 1;
1089 }
1090
zbao2c08f6a2012-07-02 15:32:58 +08001091 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -08001092 if (dev->path.type == DEVICE_PATH_DOMAIN) {
zbao2c08f6a2012-07-02 15:32:58 +08001093 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -08001094 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
zbao2c08f6a2012-07-02 15:32:58 +08001095 dev->ops = &cpu_bus_ops;
1096 }
1097}
1098
1099struct chip_operations northbridge_amd_agesa_family15tn_root_complex_ops = {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001100 CHIP_NAME("AMD FAM15tn Root Complex")
zbao2c08f6a2012-07-02 15:32:58 +08001101 .enable_dev = root_complex_enable_dev,
1102};
Dave Frodincbf3d402012-12-05 08:20:12 -07001103
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001104/*********************************************************************
1105 * Change the vendor / device IDs to match the generic VBIOS header. *
1106 *********************************************************************/
Dave Frodincbf3d402012-12-05 08:20:12 -07001107u32 map_oprom_vendev(u32 vendev)
1108{
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001109 u32 new_vendev = vendev;
Dave Frodincbf3d402012-12-05 08:20:12 -07001110
1111 switch(vendev) {
Bruce Griffith42e11f52013-07-08 18:19:08 -06001112 case 0x10029900: /* AMD Radeon HD 7660G (Trinity) */
1113 case 0x10029901: /* AMD Radeon HD 7660D (Trinity) */
1114 case 0x10029903: /* AMD Radeon HD 7640G (Trinity) */
1115 case 0x10029904: /* AMD Radeon HD 7560D (Trinity) */
1116 case 0x10029907: /* AMD Radeon HD 7620G (Trinity) */
1117 case 0x10029908: /* AMD Radeon HD 7600G (Trinity) */
1118 case 0x1002990A: /* AMD Radeon HD 7500G (Trinity) */
1119 case 0x1002990B: /* AMD Radeon HD 8650G (Richland) */
1120 case 0x1002990C: /* AMD Radeon HD 8670D (Richland) */
1121 case 0x1002990D: /* AMD Radeon HD 8550G (Richland) */
1122 case 0x1002990E: /* AMD Radeon HD 8570D (Richland) */
1123 case 0x1002990F: /* AMD Radeon HD 8610G (Richland) */
1124 case 0x10029910: /* AMD Radeon HD 7660G (Trinity) */
1125 case 0x10029913: /* AMD Radeon HD 7640G (Trinity) */
1126 case 0x10029917: /* AMD Radeon HD 7620G (Trinity) */
1127 case 0x10029918: /* AMD Radeon HD 7600G (Trinity) */
1128 case 0x10029919: /* AMD Radeon HD 7500G (Trinity) */
1129 case 0x10029990: /* AMD Radeon HD 7520G (Trinity) */
1130 case 0x10029991: /* AMD Radeon HD 7540D (Trinity) */
1131 case 0x10029992: /* AMD Radeon HD 7420G (Trinity) */
1132 case 0x10029993: /* AMD Radeon HD 7480D (Trinity) */
1133 case 0x10029994: /* AMD Radeon HD 7400G (Trinity) */
1134 case 0x10029995: /* AMD Radeon HD 8450G (Richland) */
1135 case 0x10029996: /* AMD Radeon HD 8470D (Richland) */
1136 case 0x10029997: /* AMD Radeon HD 8350G (Richland) */
1137 case 0x10029998: /* AMD Radeon HD 8370D (Richland) */
1138 case 0x10029999: /* AMD Radeon HD 8510G (Richland) */
1139 case 0x1002999A: /* AMD Radeon HD 8410G (Richland) */
1140 case 0x1002999B: /* AMD Radeon HD 8310G (Richland) */
1141 case 0x1002999C: /* AMD Radeon HD 8650D (Richland) */
1142 case 0x1002999D: /* AMD Radeon HD 8550D (Richland) */
1143 case 0x100299A0: /* AMD Radeon HD 7520G (Trinity) */
1144 case 0x100299A2: /* AMD Radeon HD 7420G (Trinity) */
1145 case 0x100299A4: /* AMD Radeon HD 7400G (Trinity) */
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001146 new_vendev = 0x10029901;
Dave Frodincbf3d402012-12-05 08:20:12 -07001147 break;
1148 }
1149
1150 return new_vendev;
1151}