blob: 95787fc867dca5c8800d8f8c9d8af5017fc57e1f [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
zbao2c08f6a2012-07-02 15:32:58 +0800697static void domain_set_resources(device_t dev)
698{
zbao2c08f6a2012-07-02 15:32:58 +0800699 unsigned long mmio_basek;
700 u32 pci_tolm;
701 int i, idx;
702 struct bus *link;
703#if CONFIG_HW_MEM_HOLE_SIZEK != 0
704 struct hw_mem_hole_info mem_hole;
705 u32 reset_memhole = 1;
706#endif
707
zbao2c08f6a2012-07-02 15:32:58 +0800708 pci_tolm = 0xffffffffUL;
709 for (link = dev->link_list; link; link = link->next) {
710 pci_tolm = find_pci_tolm(link);
711 }
712
713 // FIXME handle interleaved nodes. If you fix this here, please fix
714 // amdk8, too.
715 mmio_basek = pci_tolm >> 10;
716 /* Round mmio_basek to something the processor can support */
717 mmio_basek &= ~((1 << 6) -1);
718
719 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
720 // MMIO hole. If you fix this here, please fix amdk8, too.
721 /* Round the mmio hole to 64M */
722 mmio_basek &= ~((64*1024) - 1);
723
724#if CONFIG_HW_MEM_HOLE_SIZEK != 0
725 /* if the hw mem hole is already set in raminit stage, here we will compare
726 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
727 * use hole_basek as mmio_basek and we don't need to reset hole.
728 * otherwise We reset the hole to the mmio_basek
729 */
730
731 mem_hole = get_hw_mem_hole_info();
732
733 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
734 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
735 mmio_basek = mem_hole.hole_startk;
736 reset_memhole = 0;
737 }
738#endif
739
740 idx = 0x10;
741 for (i = 0; i < node_nums; i++) {
742 dram_base_mask_t d;
743 resource_t basek, limitk, sizek; // 4 1T
744
745 d = get_dram_base_mask(i);
746
747 if (!(d.mask & 1)) continue;
748 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100749 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800750
751 sizek = limitk - basek;
752
753 /* see if we need a hole from 0xa0000 to 0xbffff */
754 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
755 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
756 idx += 0x10;
757 basek = (8*64)+(16*16);
758 sizek = limitk - ((8*64)+(16*16));
759
760 }
761
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300762 /* split the region to accommodate pci memory space */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200763 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
zbao2c08f6a2012-07-02 15:32:58 +0800764 if (basek <= mmio_basek) {
765 unsigned pre_sizek;
766 pre_sizek = mmio_basek - basek;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200767 if (pre_sizek > 0) {
zbao2c08f6a2012-07-02 15:32:58 +0800768 ram_resource(dev, (idx | i), basek, pre_sizek);
769 idx += 0x10;
770 sizek -= pre_sizek;
zbao2c08f6a2012-07-02 15:32:58 +0800771 }
772 basek = mmio_basek;
773 }
774 if ((basek + sizek) <= 4*1024*1024) {
775 sizek = 0;
776 }
777 else {
Siyuan Wang29840e22013-06-04 19:56:22 +0800778 uint64_t topmem2 = bsp_topmem2();
zbao2c08f6a2012-07-02 15:32:58 +0800779 basek = 4*1024*1024;
Siyuan Wang29840e22013-06-04 19:56:22 +0800780 sizek = topmem2/1024 - basek;
zbao2c08f6a2012-07-02 15:32:58 +0800781 }
782 }
783
zbao2c08f6a2012-07-02 15:32:58 +0800784 ram_resource(dev, (idx | i), basek, sizek);
785 idx += 0x10;
zbao2c08f6a2012-07-02 15:32:58 +0800786 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
787 i, mmio_basek, basek, limitk);
zbao2c08f6a2012-07-02 15:32:58 +0800788 }
789
Kyösti Mälkki61be3602017-04-15 20:07:53 +0300790 add_uma_resource_below_tolm(dev, 7);
zbao2c08f6a2012-07-02 15:32:58 +0800791
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200792 for (link = dev->link_list; link; link = link->next) {
zbao2c08f6a2012-07-02 15:32:58 +0800793 if (link->children) {
794 assign_resources(link);
795 }
796 }
797}
798
799static struct device_operations pci_domain_ops = {
800 .read_resources = domain_read_resources,
801 .set_resources = domain_set_resources,
802 .enable_resources = domain_enable_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100803 .init = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +0800804 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki872c9222013-07-03 09:44:28 +0300805 .ops_pci_bus = pci_bus_default_ops,
zbao2c08f6a2012-07-02 15:32:58 +0800806};
807
808static void sysconf_init(device_t dev) // first node
809{
810 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
811 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
812}
813
814static void add_more_links(device_t dev, unsigned total_links)
815{
816 struct bus *link, *last = NULL;
817 int link_num;
818
819 for (link = dev->link_list; link; link = link->next)
820 last = link;
821
822 if (last) {
823 int links = total_links - last->link_num;
824 link_num = last->link_num;
825 if (links > 0) {
826 link = malloc(links*sizeof(*link));
827 if (!link)
828 die("Couldn't allocate more links!\n");
829 memset(link, 0, links*sizeof(*link));
830 last->next = link;
831 }
832 }
833 else {
834 link_num = -1;
835 link = malloc(total_links*sizeof(*link));
836 memset(link, 0, total_links*sizeof(*link));
837 dev->link_list = link;
838 }
839
840 for (link_num = link_num + 1; link_num < total_links; link_num++) {
841 link->link_num = link_num;
842 link->dev = dev;
843 link->next = link + 1;
844 last = link;
845 link = link->next;
846 }
847 last->next = NULL;
848}
849
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200850static void cpu_bus_scan(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800851{
852 struct bus *cpu_bus;
853 device_t dev_mc;
854#if CONFIG_CBB
855 device_t pci_domain;
856#endif
857 int i,j;
858 int coreid_bits;
859 int core_max = 0;
860 unsigned ApicIdCoreIdSize;
861 unsigned core_nums;
862 int siblings = 0;
863 unsigned int family;
864
865#if CONFIG_CBB
866 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
867 if (dev_mc && dev_mc->bus) {
868 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
869 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800870 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800871 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
872 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
873 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
874 } else {
875 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
876 }
877 printk(BIOS_DEBUG, "\n");
878 }
879 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
880 if (!dev_mc) {
881 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
882 if (dev_mc && dev_mc->bus) {
883 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
884 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800885 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800886 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
887 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
888 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
889 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
890 while (dev_mc) {
891 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
892 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
893 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
894 dev_mc = dev_mc->sibling;
895 }
896 }
897 }
898 }
899 }
900#endif
901 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
902 if (!dev_mc) {
903 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
904 die("");
905 }
906 sysconf_init(dev_mc);
907#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200908 if (node_nums > 32) { // need to put node 32 to node 63 to bus 0xfe
zbao2c08f6a2012-07-02 15:32:58 +0800909 if (pci_domain->link_list && !pci_domain->link_list->next) {
910 struct bus *new_link = new_link(pci_domain);
911 pci_domain->link_list->next = new_link;
912 new_link->link_num = 1;
913 new_link->dev = pci_domain;
914 new_link->children = 0;
915 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
916 }
917 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
918 }
919#endif
920
921 /* Get Max Number of cores(MNC) */
922 coreid_bits = (cpuid_ecx(AMD_CPUID_ASIZE_PCCOUNT) & 0x0000F000) >> 12;
923 core_max = 1 << (coreid_bits & 0x000F); //mnc
924
925 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
926 if (ApicIdCoreIdSize) {
927 core_nums = (1 << ApicIdCoreIdSize) - 1;
928 } else {
929 core_nums = 3; //quad core
930 }
931
932 /* Find which cpus are present */
933 cpu_bus = dev->link_list;
934 for (i = 0; i < node_nums; i++) {
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300935 device_t cdb_dev;
zbao2c08f6a2012-07-02 15:32:58 +0800936 unsigned busn, devn;
937 struct bus *pbus;
938
939 busn = CONFIG_CBB;
940 devn = CONFIG_CDB + i;
941 pbus = dev_mc->bus;
942#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
943 if (i >= 32) {
944 busn--;
945 devn -= 32;
946 pbus = pci_domain->link_list->next;
947 }
948#endif
949
950 /* Find the cpu's pci device */
951 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
952 if (!cdb_dev) {
953 /* If I am probing things in a weird order
954 * ensure all of the cpu's pci devices are found.
955 */
956 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200957 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
zbao2c08f6a2012-07-02 15:32:58 +0800958 cdb_dev = pci_probe_dev(NULL, pbus,
959 PCI_DEVFN(devn, fn));
960 }
961 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
962 } else {
963 /* Ok, We need to set the links for that device.
964 * otherwise the device under it will not be scanned
965 */
Kyösti Mälkki2a2d6132015-02-04 13:25:37 +0200966 add_more_links(cdb_dev, 4);
zbao2c08f6a2012-07-02 15:32:58 +0800967 }
968
969 family = cpuid_eax(1);
970 family = (family >> 20) & 0xFF;
971 if (family == 1) { //f10
972 u32 dword;
973 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
974 dword = pci_read_config32(cdb_dev, 0xe8);
975 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
976 } else if (family == 6) {//f15
977 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
978 if (cdb_dev && cdb_dev->enabled) {
979 siblings = pci_read_config32(cdb_dev, 0x84);
980 siblings &= 0xFF;
981 }
982 } else {
983 siblings = 0; //default one core
984 }
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300985 int enable_node = cdb_dev && cdb_dev->enabled;
zbao2c08f6a2012-07-02 15:32:58 +0800986 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
987 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
988
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200989 for (j = 0; j <= siblings; j++) {
zbao2c08f6a2012-07-02 15:32:58 +0800990 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
991 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
992 u32 lapicid_start = 0;
993
zbao2c08f6a2012-07-02 15:32:58 +0800994 /*
995 * APIC ID calucation is tightly coupled with AGESA v5 code.
996 * This calculation MUST match the assignment calculation done
997 * in LocalApicInitializationAtEarly() function.
998 * And reference GetLocalApicIdForCore()
999 *
1000 * Apply apic enumeration rules
1001 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1002 * put the local-APICs at m..z
1003 *
1004 * This is needed because many IO-APIC devices only have 4 bits
1005 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001006 */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001007
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001008 u8 plat_num_io_apics = 3; /* FIXME */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001009
1010 if ((node_nums * core_max) + plat_num_io_apics >= 0x10) {
1011 lapicid_start = (plat_num_io_apics - 1) / core_max;
zbao2c08f6a2012-07-02 15:32:58 +08001012 lapicid_start = (lapicid_start + 1) * core_max;
1013 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
1014 }
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001015 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
zbao2c08f6a2012-07-02 15:32:58 +08001016 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001017 i, j, apic_id);
zbao2c08f6a2012-07-02 15:32:58 +08001018
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001019 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1020 if (cpu)
1021 amd_cpu_topology(cpu, i, j);
zbao2c08f6a2012-07-02 15:32:58 +08001022 } //j
1023 }
zbao2c08f6a2012-07-02 15:32:58 +08001024}
1025
1026static void cpu_bus_init(device_t dev)
1027{
1028 initialize_cpus(dev->link_list);
1029}
1030
zbao2c08f6a2012-07-02 15:32:58 +08001031static struct device_operations cpu_bus_ops = {
Edward O'Callaghan2837ab22014-11-06 08:57:40 +11001032 .read_resources = DEVICE_NOOP,
1033 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001034 .enable_resources = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +08001035 .init = cpu_bus_init,
1036 .scan_bus = cpu_bus_scan,
1037};
1038
1039static void root_complex_enable_dev(struct device *dev)
1040{
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001041 static int done = 0;
1042
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001043 if (!done) {
1044 setup_bsp_ramtop();
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001045 done = 1;
1046 }
1047
zbao2c08f6a2012-07-02 15:32:58 +08001048 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -08001049 if (dev->path.type == DEVICE_PATH_DOMAIN) {
zbao2c08f6a2012-07-02 15:32:58 +08001050 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -08001051 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
zbao2c08f6a2012-07-02 15:32:58 +08001052 dev->ops = &cpu_bus_ops;
1053 }
1054}
1055
1056struct chip_operations northbridge_amd_agesa_family15tn_root_complex_ops = {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001057 CHIP_NAME("AMD FAM15tn Root Complex")
zbao2c08f6a2012-07-02 15:32:58 +08001058 .enable_dev = root_complex_enable_dev,
1059};
Dave Frodincbf3d402012-12-05 08:20:12 -07001060
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001061/*********************************************************************
1062 * Change the vendor / device IDs to match the generic VBIOS header. *
1063 *********************************************************************/
Dave Frodincbf3d402012-12-05 08:20:12 -07001064u32 map_oprom_vendev(u32 vendev)
1065{
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001066 u32 new_vendev = vendev;
Dave Frodincbf3d402012-12-05 08:20:12 -07001067
1068 switch(vendev) {
Bruce Griffith42e11f52013-07-08 18:19:08 -06001069 case 0x10029900: /* AMD Radeon HD 7660G (Trinity) */
1070 case 0x10029901: /* AMD Radeon HD 7660D (Trinity) */
1071 case 0x10029903: /* AMD Radeon HD 7640G (Trinity) */
1072 case 0x10029904: /* AMD Radeon HD 7560D (Trinity) */
1073 case 0x10029907: /* AMD Radeon HD 7620G (Trinity) */
1074 case 0x10029908: /* AMD Radeon HD 7600G (Trinity) */
1075 case 0x1002990A: /* AMD Radeon HD 7500G (Trinity) */
1076 case 0x1002990B: /* AMD Radeon HD 8650G (Richland) */
1077 case 0x1002990C: /* AMD Radeon HD 8670D (Richland) */
1078 case 0x1002990D: /* AMD Radeon HD 8550G (Richland) */
1079 case 0x1002990E: /* AMD Radeon HD 8570D (Richland) */
1080 case 0x1002990F: /* AMD Radeon HD 8610G (Richland) */
1081 case 0x10029910: /* AMD Radeon HD 7660G (Trinity) */
1082 case 0x10029913: /* AMD Radeon HD 7640G (Trinity) */
1083 case 0x10029917: /* AMD Radeon HD 7620G (Trinity) */
1084 case 0x10029918: /* AMD Radeon HD 7600G (Trinity) */
1085 case 0x10029919: /* AMD Radeon HD 7500G (Trinity) */
1086 case 0x10029990: /* AMD Radeon HD 7520G (Trinity) */
1087 case 0x10029991: /* AMD Radeon HD 7540D (Trinity) */
1088 case 0x10029992: /* AMD Radeon HD 7420G (Trinity) */
1089 case 0x10029993: /* AMD Radeon HD 7480D (Trinity) */
1090 case 0x10029994: /* AMD Radeon HD 7400G (Trinity) */
1091 case 0x10029995: /* AMD Radeon HD 8450G (Richland) */
1092 case 0x10029996: /* AMD Radeon HD 8470D (Richland) */
1093 case 0x10029997: /* AMD Radeon HD 8350G (Richland) */
1094 case 0x10029998: /* AMD Radeon HD 8370D (Richland) */
1095 case 0x10029999: /* AMD Radeon HD 8510G (Richland) */
1096 case 0x1002999A: /* AMD Radeon HD 8410G (Richland) */
1097 case 0x1002999B: /* AMD Radeon HD 8310G (Richland) */
1098 case 0x1002999C: /* AMD Radeon HD 8650D (Richland) */
1099 case 0x1002999D: /* AMD Radeon HD 8550D (Richland) */
1100 case 0x100299A0: /* AMD Radeon HD 7520G (Trinity) */
1101 case 0x100299A2: /* AMD Radeon HD 7420G (Trinity) */
1102 case 0x100299A4: /* AMD Radeon HD 7400G (Trinity) */
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001103 new_vendev = 0x10029901;
Dave Frodincbf3d402012-12-05 08:20:12 -07001104 break;
1105 }
1106
1107 return new_vendev;
1108}