blob: 675be14182fa72608df3c152d1a7c969cfe23b6b [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.
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +03005 * Copyright (C) 2014 Edward O'Callaghan <eocallaghan@alterapraxis.com>
zbao2c08f6a2012-07-02 15:32:58 +08006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
zbao2c08f6a2012-07-02 15:32:58 +080015 */
16
17#include <console/console.h>
18#include <arch/io.h>
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +030019#include <arch/acpi.h>
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +020020#include <arch/acpigen.h>
zbao2c08f6a2012-07-02 15:32:58 +080021#include <stdint.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
25#include <device/hypertransport.h>
26#include <stdlib.h>
27#include <string.h>
Ronald G. Minnich5079a0d2012-11-27 11:32:38 -080028#include <lib.h>
zbao2c08f6a2012-07-02 15:32:58 +080029#include <cpu/cpu.h>
30#include <cbmem.h>
Martin Roth73e86a82013-01-17 16:28:30 -070031#include <AGESA.h>
zbao2c08f6a2012-07-02 15:32:58 +080032
33#include <cpu/x86/lapic.h>
Kyösti Mälkkidbc47392012-08-05 12:11:40 +030034#include <cpu/amd/mtrr.h>
zbao2c08f6a2012-07-02 15:32:58 +080035
36#include <Porting.h>
zbao2c08f6a2012-07-02 15:32:58 +080037#include <Options.h>
38#include <Topology.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020039
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030040#include <northbridge/amd/agesa/agesawrapper.h>
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020041#include <northbridge/amd/agesa/state_machine.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]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020068 d.mask |= temp << 21;
zbao2c08f6a2012-07-02 15:32:58 +080069 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]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020073 d.base |= temp << 21;
zbao2c08f6a2012-07-02 15:32:58 +080074 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 */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020083 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 HAOUAS27e18012017-06-27 23:14:51 +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 */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020096 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
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300155static u32 amdfam15_nodeid(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800156{
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
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200175 val = 1 | (nodeid << 4) | (linkn << 12);
zbao2c08f6a2012-07-02 15:32:58 +0800176 /* 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 */
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300190static int reg_useable(unsigned reg, struct device *goal_dev, unsigned goal_nodeid,
zbao2c08f6a2012-07-02 15:32:58 +0800191 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++) {
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300198 struct device *dev;
zbao2c08f6a2012-07-02 15:32:58 +0800199 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
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300218static struct resource *amdfam15_find_iopair(struct device *dev, unsigned nodeid, unsigned link)
zbao2c08f6a2012-07-02 15:32:58 +0800219{
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
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300245static struct resource *amdfam15_find_mempair(struct device *dev, u32 nodeid, u32 link)
zbao2c08f6a2012-07-02 15:32:58 +0800246{
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
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300271static void amdfam15_link_read_bases(struct device *dev, u32 nodeid, u32 link)
zbao2c08f6a2012-07-02 15:32:58 +0800272{
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
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300313static void nb_read_resources(struct device *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
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300333static void set_resource(struct device *dev, struct resource *resource, u32 nodeid)
zbao2c08f6a2012-07-02 15:32:58 +0800334{
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
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300384static void create_vga_resource(struct device *dev, unsigned nodeid)
zbao2c08f6a2012-07-02 15:32:58 +0800385{
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) {
Martin Roth77a58b92017-06-24 14:45:48 -0600392#if IS_ENABLED(CONFIG_MULTIPLE_VGA_ADAPTERS)
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300393 extern struct device *vga_pri; // the primary vga device, defined in device.c
zbao2c08f6a2012-07-02 15:32:58 +0800394 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) &&
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300398 (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
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300412static void nb_set_resources(struct device *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 +0100435static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200436{
437 void *addr, *current;
438
439 /* Skip the HEST header. */
440 current = (void *)(hest + 1);
441
442 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
443 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700444 current += acpi_create_hest_error_source(hest, current, 0,
445 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200446
447 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
448 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700449 current += acpi_create_hest_error_source(hest, current, 1,
450 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200451
452 return (unsigned long)current;
453}
454
Alexander Couzens5eea4582015-04-12 22:18:55 +0200455static void northbridge_fill_ssdt_generator(device_t device)
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200456{
457 msr_t msr;
458 char pscope[] = "\\_SB.PCI0";
459
460 acpigen_write_scope(pscope);
461 msr = rdmsr(TOP_MEM);
462 acpigen_write_name_dword("TOM1", msr.lo);
463 msr = rdmsr(TOP_MEM2);
464 /*
465 * Since XP only implements parts of ACPI 2.0, we can't use a qword
466 * here.
467 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
468 * slide 22ff.
469 * Shift value right by 20 bit to make it fit into 32bit,
470 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
471 */
472 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
473 acpigen_pop_len();
474}
475
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200476static unsigned long agesa_write_acpi_tables(device_t device,
477 unsigned long current,
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200478 acpi_rsdp_t *rsdp)
479{
480 acpi_srat_t *srat;
481 acpi_slit_t *slit;
482 acpi_header_t *ssdt;
483 acpi_header_t *alib;
484 acpi_header_t *ivrs;
485 acpi_hest_t *hest;
486
487 /* HEST */
488 current = ALIGN(current, 8);
489 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100490 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200491 acpi_add_table(rsdp, (void *)current);
492 current += ((acpi_header_t *)current)->length;
493
494 current = ALIGN(current, 8);
495 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
496 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
497 if (ivrs != NULL) {
498 memcpy((void *)current, ivrs, ivrs->length);
499 ivrs = (acpi_header_t *) current;
500 current += ivrs->length;
501 acpi_add_table(rsdp, ivrs);
502 } else {
503 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
504 }
505
506 /* SRAT */
507 current = ALIGN(current, 8);
508 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
509 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
510 if (srat != NULL) {
511 memcpy((void *)current, srat, srat->header.length);
512 srat = (acpi_srat_t *) current;
513 current += srat->header.length;
514 acpi_add_table(rsdp, srat);
515 } else {
516 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
517 }
518
519 /* SLIT */
520 current = ALIGN(current, 8);
521 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
522 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
523 if (slit != NULL) {
524 memcpy((void *)current, slit, slit->header.length);
525 slit = (acpi_slit_t *) current;
526 current += slit->header.length;
527 acpi_add_table(rsdp, slit);
528 } else {
529 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
530 }
531
532 /* ALIB */
533 current = ALIGN(current, 16);
534 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
535 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
536 if (alib != NULL) {
537 memcpy((void *)current, alib, alib->length);
538 alib = (acpi_header_t *) current;
539 current += alib->length;
540 acpi_add_table(rsdp, (void *)alib);
541 }
542 else {
543 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
544 }
545
546 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
547 /* SSDT */
548 current = ALIGN(current, 16);
549 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
550 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
551 if (ssdt != NULL) {
552 memcpy((void *)current, ssdt, ssdt->length);
553 ssdt = (acpi_header_t *) current;
554 current += ssdt->length;
555 }
556 else {
557 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
558 }
559 acpi_add_table(rsdp,ssdt);
560
561 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
562
563 return current;
564}
565
566
zbao2c08f6a2012-07-02 15:32:58 +0800567static struct device_operations northbridge_operations = {
Steven Sherkf4340582013-01-29 16:13:35 -0700568 .read_resources = nb_read_resources,
569 .set_resources = nb_set_resources,
zbao2c08f6a2012-07-02 15:32:58 +0800570 .enable_resources = pci_dev_enable_resources,
Edward O'Callaghand994ef12014-11-21 02:22:33 +1100571 .init = DEVICE_NOOP,
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200572 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
573 .write_acpi_tables = agesa_write_acpi_tables,
zbao2c08f6a2012-07-02 15:32:58 +0800574 .enable = 0,
575 .ops_pci = 0,
576};
577
578static const struct pci_driver family15_northbridge __pci_driver = {
579 .ops = &northbridge_operations,
580 .vendor = PCI_VENDOR_ID_AMD,
Marshall Dawson463f46e2016-10-14 20:46:08 -0600581 .device = PCI_DEVICE_ID_AMD_15H_MODEL_101F_NB_HT,
zbao2c08f6a2012-07-02 15:32:58 +0800582};
583
584static const struct pci_driver family10_northbridge __pci_driver = {
585 .ops = &northbridge_operations,
586 .vendor = PCI_VENDOR_ID_AMD,
587 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
588};
589
590struct chip_operations northbridge_amd_agesa_family15tn_ops = {
591 CHIP_NAME("AMD FAM15 Northbridge")
592 .enable_dev = 0,
593};
594
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300595static void domain_read_resources(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800596{
597 unsigned reg;
598
599 /* Find the already assigned resource pairs */
600 get_fx_devs();
601 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
602 u32 base, limit;
603 base = f1_read_config32(reg);
604 limit = f1_read_config32(reg + 0x04);
605 /* Is this register allocated? */
606 if ((base & 3) != 0) {
607 unsigned nodeid, reg_link;
608 device_t reg_dev;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200609 if (reg < 0xc0) { // mmio
zbao2c08f6a2012-07-02 15:32:58 +0800610 nodeid = (limit & 0xf) + (base&0x30);
611 } else { // io
612 nodeid = (limit & 0xf) + ((base>>4)&0x30);
613 }
614 reg_link = (limit >> 4) & 7;
615 reg_dev = __f0_dev[nodeid];
616 if (reg_dev) {
617 /* Reserve the resource */
618 struct resource *res;
619 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
620 if (res) {
621 res->flags = 1;
622 }
623 }
624 }
625 }
626 /* FIXME: do we need to check extend conf space?
627 I don't believe that much preset value */
628
zbao2c08f6a2012-07-02 15:32:58 +0800629 pci_domain_read_resources(dev);
zbao2c08f6a2012-07-02 15:32:58 +0800630}
631
zbao2c08f6a2012-07-02 15:32:58 +0800632static void domain_enable_resources(device_t dev)
633{
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200634#if IS_ENABLED(CONFIG_AGESA_LEGACY_WRAPPER)
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__);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200646#endif
zbao2c08f6a2012-07-02 15:32:58 +0800647}
648
649#if CONFIG_HW_MEM_HOLE_SIZEK != 0
650struct hw_mem_hole_info {
651 unsigned hole_startk;
652 int node_id;
653};
654static struct hw_mem_hole_info get_hw_mem_hole_info(void)
655{
656 struct hw_mem_hole_info mem_hole;
657 int i;
658 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
659 mem_hole.node_id = -1;
660 for (i = 0; i < node_nums; i++) {
661 dram_base_mask_t d;
662 u32 hole;
663 d = get_dram_base_mask(i);
664 if (!(d.mask & 1)) continue; // no memory on this node
665 hole = pci_read_config32(__f1_dev[i], 0xf0);
666 if (hole & 1) { // we find the hole
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200667 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
zbao2c08f6a2012-07-02 15:32:58 +0800668 mem_hole.node_id = i; // record the node No with hole
669 break; // only one hole
670 }
671 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300672
673 /* We need to double check if there is special set on base reg and limit reg
674 * are not continuous instead of hole, it will find out its hole_startk.
675 */
zbao2c08f6a2012-07-02 15:32:58 +0800676 if (mem_hole.node_id == -1) {
677 resource_t limitk_pri = 0;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200678 for (i = 0; i < node_nums; i++) {
zbao2c08f6a2012-07-02 15:32:58 +0800679 dram_base_mask_t d;
680 resource_t base_k, limit_k;
681 d = get_dram_base_mask(i);
682 if (!(d.base & 1)) continue;
683 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
684 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
685 if (limitk_pri != base_k) { // we find the hole
686 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
687 mem_hole.node_id = i;
688 break; //only one hole
689 }
zbao15dc3cc2012-08-03 15:56:21 +0800690 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800691 limitk_pri = limit_k;
692 }
693 }
694 return mem_hole;
695}
696#endif
697
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300698static void domain_set_resources(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800699{
zbao2c08f6a2012-07-02 15:32:58 +0800700 unsigned long mmio_basek;
701 u32 pci_tolm;
702 int i, idx;
703 struct bus *link;
704#if CONFIG_HW_MEM_HOLE_SIZEK != 0
705 struct hw_mem_hole_info mem_hole;
706 u32 reset_memhole = 1;
707#endif
708
zbao2c08f6a2012-07-02 15:32:58 +0800709 pci_tolm = 0xffffffffUL;
710 for (link = dev->link_list; link; link = link->next) {
711 pci_tolm = find_pci_tolm(link);
712 }
713
714 // FIXME handle interleaved nodes. If you fix this here, please fix
715 // amdk8, too.
716 mmio_basek = pci_tolm >> 10;
717 /* Round mmio_basek to something the processor can support */
718 mmio_basek &= ~((1 << 6) -1);
719
720 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
721 // MMIO hole. If you fix this here, please fix amdk8, too.
722 /* Round the mmio hole to 64M */
723 mmio_basek &= ~((64*1024) - 1);
724
725#if CONFIG_HW_MEM_HOLE_SIZEK != 0
726 /* if the hw mem hole is already set in raminit stage, here we will compare
727 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
728 * use hole_basek as mmio_basek and we don't need to reset hole.
729 * otherwise We reset the hole to the mmio_basek
730 */
731
732 mem_hole = get_hw_mem_hole_info();
733
734 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
735 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
736 mmio_basek = mem_hole.hole_startk;
737 reset_memhole = 0;
738 }
739#endif
740
741 idx = 0x10;
742 for (i = 0; i < node_nums; i++) {
743 dram_base_mask_t d;
744 resource_t basek, limitk, sizek; // 4 1T
745
746 d = get_dram_base_mask(i);
747
748 if (!(d.mask & 1)) continue;
749 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100750 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800751
752 sizek = limitk - basek;
753
754 /* see if we need a hole from 0xa0000 to 0xbffff */
755 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
756 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
757 idx += 0x10;
758 basek = (8*64)+(16*16);
759 sizek = limitk - ((8*64)+(16*16));
760
761 }
762
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300763 /* split the region to accommodate pci memory space */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200764 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
zbao2c08f6a2012-07-02 15:32:58 +0800765 if (basek <= mmio_basek) {
766 unsigned pre_sizek;
767 pre_sizek = mmio_basek - basek;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200768 if (pre_sizek > 0) {
zbao2c08f6a2012-07-02 15:32:58 +0800769 ram_resource(dev, (idx | i), basek, pre_sizek);
770 idx += 0x10;
771 sizek -= pre_sizek;
zbao2c08f6a2012-07-02 15:32:58 +0800772 }
773 basek = mmio_basek;
774 }
775 if ((basek + sizek) <= 4*1024*1024) {
776 sizek = 0;
777 }
778 else {
Siyuan Wang29840e22013-06-04 19:56:22 +0800779 uint64_t topmem2 = bsp_topmem2();
zbao2c08f6a2012-07-02 15:32:58 +0800780 basek = 4*1024*1024;
Siyuan Wang29840e22013-06-04 19:56:22 +0800781 sizek = topmem2/1024 - basek;
zbao2c08f6a2012-07-02 15:32:58 +0800782 }
783 }
784
zbao2c08f6a2012-07-02 15:32:58 +0800785 ram_resource(dev, (idx | i), basek, sizek);
786 idx += 0x10;
zbao2c08f6a2012-07-02 15:32:58 +0800787 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
788 i, mmio_basek, basek, limitk);
zbao2c08f6a2012-07-02 15:32:58 +0800789 }
790
Kyösti Mälkki61be3602017-04-15 20:07:53 +0300791 add_uma_resource_below_tolm(dev, 7);
zbao2c08f6a2012-07-02 15:32:58 +0800792
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200793 for (link = dev->link_list; link; link = link->next) {
zbao2c08f6a2012-07-02 15:32:58 +0800794 if (link->children) {
795 assign_resources(link);
796 }
797 }
798}
799
800static struct device_operations pci_domain_ops = {
801 .read_resources = domain_read_resources,
802 .set_resources = domain_set_resources,
803 .enable_resources = domain_enable_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100804 .init = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +0800805 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki872c9222013-07-03 09:44:28 +0300806 .ops_pci_bus = pci_bus_default_ops,
zbao2c08f6a2012-07-02 15:32:58 +0800807};
808
809static void sysconf_init(device_t dev) // first node
810{
811 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
812 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
813}
814
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300815static void add_more_links(struct device *dev, unsigned total_links)
zbao2c08f6a2012-07-02 15:32:58 +0800816{
817 struct bus *link, *last = NULL;
818 int link_num;
819
820 for (link = dev->link_list; link; link = link->next)
821 last = link;
822
823 if (last) {
824 int links = total_links - last->link_num;
825 link_num = last->link_num;
826 if (links > 0) {
827 link = malloc(links*sizeof(*link));
828 if (!link)
829 die("Couldn't allocate more links!\n");
830 memset(link, 0, links*sizeof(*link));
831 last->next = link;
832 }
833 }
834 else {
835 link_num = -1;
836 link = malloc(total_links*sizeof(*link));
837 memset(link, 0, total_links*sizeof(*link));
838 dev->link_list = link;
839 }
840
841 for (link_num = link_num + 1; link_num < total_links; link_num++) {
842 link->link_num = link_num;
843 link->dev = dev;
844 link->next = link + 1;
845 last = link;
846 link = link->next;
847 }
848 last->next = NULL;
849}
850
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200851static void cpu_bus_scan(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800852{
853 struct bus *cpu_bus;
854 device_t dev_mc;
855#if CONFIG_CBB
856 device_t pci_domain;
857#endif
858 int i,j;
859 int coreid_bits;
860 int core_max = 0;
861 unsigned ApicIdCoreIdSize;
862 unsigned core_nums;
863 int siblings = 0;
864 unsigned int family;
865
866#if CONFIG_CBB
867 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
868 if (dev_mc && dev_mc->bus) {
869 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
870 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800871 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800872 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
873 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
874 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
875 } else {
876 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
877 }
878 printk(BIOS_DEBUG, "\n");
879 }
880 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
881 if (!dev_mc) {
882 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
883 if (dev_mc && dev_mc->bus) {
884 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
885 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800886 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800887 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
888 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
889 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
890 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
891 while (dev_mc) {
892 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
893 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
894 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
895 dev_mc = dev_mc->sibling;
896 }
897 }
898 }
899 }
900 }
901#endif
902 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
903 if (!dev_mc) {
904 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
905 die("");
906 }
907 sysconf_init(dev_mc);
908#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200909 if (node_nums > 32) { // need to put node 32 to node 63 to bus 0xfe
zbao2c08f6a2012-07-02 15:32:58 +0800910 if (pci_domain->link_list && !pci_domain->link_list->next) {
911 struct bus *new_link = new_link(pci_domain);
912 pci_domain->link_list->next = new_link;
913 new_link->link_num = 1;
914 new_link->dev = pci_domain;
915 new_link->children = 0;
916 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
917 }
918 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
919 }
920#endif
921
922 /* Get Max Number of cores(MNC) */
Kyösti Mälkkid41feed2017-09-24 16:23:57 +0300923 coreid_bits = (cpuid_ecx(0x80000008) & 0x0000F000) >> 12;
zbao2c08f6a2012-07-02 15:32:58 +0800924 core_max = 1 << (coreid_bits & 0x000F); //mnc
925
926 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
927 if (ApicIdCoreIdSize) {
928 core_nums = (1 << ApicIdCoreIdSize) - 1;
929 } else {
930 core_nums = 3; //quad core
931 }
932
933 /* Find which cpus are present */
934 cpu_bus = dev->link_list;
935 for (i = 0; i < node_nums; i++) {
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300936 device_t cdb_dev;
zbao2c08f6a2012-07-02 15:32:58 +0800937 unsigned busn, devn;
938 struct bus *pbus;
939
940 busn = CONFIG_CBB;
941 devn = CONFIG_CDB + i;
942 pbus = dev_mc->bus;
943#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
944 if (i >= 32) {
945 busn--;
946 devn -= 32;
947 pbus = pci_domain->link_list->next;
948 }
949#endif
950
951 /* Find the cpu's pci device */
952 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
953 if (!cdb_dev) {
954 /* If I am probing things in a weird order
955 * ensure all of the cpu's pci devices are found.
956 */
957 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200958 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
zbao2c08f6a2012-07-02 15:32:58 +0800959 cdb_dev = pci_probe_dev(NULL, pbus,
960 PCI_DEVFN(devn, fn));
961 }
962 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
963 } else {
964 /* Ok, We need to set the links for that device.
965 * otherwise the device under it will not be scanned
966 */
Kyösti Mälkki2a2d6132015-02-04 13:25:37 +0200967 add_more_links(cdb_dev, 4);
zbao2c08f6a2012-07-02 15:32:58 +0800968 }
969
970 family = cpuid_eax(1);
971 family = (family >> 20) & 0xFF;
972 if (family == 1) { //f10
973 u32 dword;
974 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
975 dword = pci_read_config32(cdb_dev, 0xe8);
976 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
977 } else if (family == 6) {//f15
978 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
979 if (cdb_dev && cdb_dev->enabled) {
980 siblings = pci_read_config32(cdb_dev, 0x84);
981 siblings &= 0xFF;
982 }
983 } else {
984 siblings = 0; //default one core
985 }
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300986 int enable_node = cdb_dev && cdb_dev->enabled;
zbao2c08f6a2012-07-02 15:32:58 +0800987 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
988 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
989
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200990 for (j = 0; j <= siblings; j++) {
zbao2c08f6a2012-07-02 15:32:58 +0800991 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
992 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
993 u32 lapicid_start = 0;
994
zbao2c08f6a2012-07-02 15:32:58 +0800995 /*
996 * APIC ID calucation is tightly coupled with AGESA v5 code.
997 * This calculation MUST match the assignment calculation done
998 * in LocalApicInitializationAtEarly() function.
999 * And reference GetLocalApicIdForCore()
1000 *
1001 * Apply apic enumeration rules
1002 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1003 * put the local-APICs at m..z
1004 *
1005 * This is needed because many IO-APIC devices only have 4 bits
1006 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001007 */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001008
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001009 u8 plat_num_io_apics = 3; /* FIXME */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001010
1011 if ((node_nums * core_max) + plat_num_io_apics >= 0x10) {
1012 lapicid_start = (plat_num_io_apics - 1) / core_max;
zbao2c08f6a2012-07-02 15:32:58 +08001013 lapicid_start = (lapicid_start + 1) * core_max;
1014 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
1015 }
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001016 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
zbao2c08f6a2012-07-02 15:32:58 +08001017 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001018 i, j, apic_id);
zbao2c08f6a2012-07-02 15:32:58 +08001019
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001020 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1021 if (cpu)
1022 amd_cpu_topology(cpu, i, j);
zbao2c08f6a2012-07-02 15:32:58 +08001023 } //j
1024 }
zbao2c08f6a2012-07-02 15:32:58 +08001025}
1026
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +03001027static void cpu_bus_init(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +08001028{
1029 initialize_cpus(dev->link_list);
1030}
1031
zbao2c08f6a2012-07-02 15:32:58 +08001032static struct device_operations cpu_bus_ops = {
Edward O'Callaghan2837ab22014-11-06 08:57:40 +11001033 .read_resources = DEVICE_NOOP,
1034 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001035 .enable_resources = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +08001036 .init = cpu_bus_init,
1037 .scan_bus = cpu_bus_scan,
1038};
1039
1040static void root_complex_enable_dev(struct device *dev)
1041{
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001042 static int done = 0;
1043
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001044 if (!done) {
1045 setup_bsp_ramtop();
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001046 done = 1;
1047 }
1048
zbao2c08f6a2012-07-02 15:32:58 +08001049 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -08001050 if (dev->path.type == DEVICE_PATH_DOMAIN) {
zbao2c08f6a2012-07-02 15:32:58 +08001051 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -08001052 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
zbao2c08f6a2012-07-02 15:32:58 +08001053 dev->ops = &cpu_bus_ops;
1054 }
1055}
1056
1057struct chip_operations northbridge_amd_agesa_family15tn_root_complex_ops = {
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +03001058 CHIP_NAME("AMD Family 15tn Root Complex")
zbao2c08f6a2012-07-02 15:32:58 +08001059 .enable_dev = root_complex_enable_dev,
1060};
Dave Frodincbf3d402012-12-05 08:20:12 -07001061
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001062/*********************************************************************
1063 * Change the vendor / device IDs to match the generic VBIOS header. *
1064 *********************************************************************/
Dave Frodincbf3d402012-12-05 08:20:12 -07001065u32 map_oprom_vendev(u32 vendev)
1066{
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001067 u32 new_vendev = vendev;
Dave Frodincbf3d402012-12-05 08:20:12 -07001068
1069 switch(vendev) {
Bruce Griffith42e11f52013-07-08 18:19:08 -06001070 case 0x10029900: /* AMD Radeon HD 7660G (Trinity) */
1071 case 0x10029901: /* AMD Radeon HD 7660D (Trinity) */
1072 case 0x10029903: /* AMD Radeon HD 7640G (Trinity) */
1073 case 0x10029904: /* AMD Radeon HD 7560D (Trinity) */
1074 case 0x10029907: /* AMD Radeon HD 7620G (Trinity) */
1075 case 0x10029908: /* AMD Radeon HD 7600G (Trinity) */
1076 case 0x1002990A: /* AMD Radeon HD 7500G (Trinity) */
1077 case 0x1002990B: /* AMD Radeon HD 8650G (Richland) */
1078 case 0x1002990C: /* AMD Radeon HD 8670D (Richland) */
1079 case 0x1002990D: /* AMD Radeon HD 8550G (Richland) */
1080 case 0x1002990E: /* AMD Radeon HD 8570D (Richland) */
1081 case 0x1002990F: /* AMD Radeon HD 8610G (Richland) */
1082 case 0x10029910: /* AMD Radeon HD 7660G (Trinity) */
1083 case 0x10029913: /* AMD Radeon HD 7640G (Trinity) */
1084 case 0x10029917: /* AMD Radeon HD 7620G (Trinity) */
1085 case 0x10029918: /* AMD Radeon HD 7600G (Trinity) */
1086 case 0x10029919: /* AMD Radeon HD 7500G (Trinity) */
1087 case 0x10029990: /* AMD Radeon HD 7520G (Trinity) */
1088 case 0x10029991: /* AMD Radeon HD 7540D (Trinity) */
1089 case 0x10029992: /* AMD Radeon HD 7420G (Trinity) */
1090 case 0x10029993: /* AMD Radeon HD 7480D (Trinity) */
1091 case 0x10029994: /* AMD Radeon HD 7400G (Trinity) */
1092 case 0x10029995: /* AMD Radeon HD 8450G (Richland) */
1093 case 0x10029996: /* AMD Radeon HD 8470D (Richland) */
1094 case 0x10029997: /* AMD Radeon HD 8350G (Richland) */
1095 case 0x10029998: /* AMD Radeon HD 8370D (Richland) */
1096 case 0x10029999: /* AMD Radeon HD 8510G (Richland) */
1097 case 0x1002999A: /* AMD Radeon HD 8410G (Richland) */
1098 case 0x1002999B: /* AMD Radeon HD 8310G (Richland) */
1099 case 0x1002999C: /* AMD Radeon HD 8650D (Richland) */
1100 case 0x1002999D: /* AMD Radeon HD 8550D (Richland) */
1101 case 0x100299A0: /* AMD Radeon HD 7520G (Trinity) */
1102 case 0x100299A2: /* AMD Radeon HD 7420G (Trinity) */
1103 case 0x100299A4: /* AMD Radeon HD 7400G (Trinity) */
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001104 new_vendev = 0x10029901;
Dave Frodincbf3d402012-12-05 08:20:12 -07001105 break;
1106 }
1107
1108 return new_vendev;
1109}