blob: b8b5e122de665900b0556240f4a2d96b45c1a759 [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>
39#include <cpu/amd/amdfam15.h>
40#include <cpuRegisters.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020041
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030042#include <northbridge/amd/agesa/agesawrapper.h>
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020043#include <northbridge/amd/agesa/state_machine.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020044#include <northbridge/amd/agesa/agesa_helper.h>
zbao2c08f6a2012-07-02 15:32:58 +080045
46#define MAX_NODE_NUMS (MAX_NODES * MAX_DIES)
47
zbao2c08f6a2012-07-02 15:32:58 +080048typedef struct dram_base_mask {
49 u32 base; //[47:27] at [28:8]
50 u32 mask; //[47:27] at [28:8] and enable at bit 0
51} dram_base_mask_t;
52
53static unsigned node_nums;
54static unsigned sblink;
55static device_t __f0_dev[MAX_NODE_NUMS];
56static device_t __f1_dev[MAX_NODE_NUMS];
57static device_t __f2_dev[MAX_NODE_NUMS];
58static device_t __f4_dev[MAX_NODE_NUMS];
59static unsigned fx_devs = 0;
60
61static dram_base_mask_t get_dram_base_mask(u32 nodeid)
62{
63 device_t dev;
64 dram_base_mask_t d;
65 dev = __f1_dev[0];
66 u32 temp;
67 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
68 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
69 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020070 d.mask |= temp << 21;
zbao2c08f6a2012-07-02 15:32:58 +080071 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
72 d.mask |= (temp & 1); // enable bit
73 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
74 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020075 d.base |= temp << 21;
zbao2c08f6a2012-07-02 15:32:58 +080076 return d;
77}
78
79static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg,
80 u32 io_min, u32 io_max)
81{
82 u32 i;
83 u32 tempreg;
84 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020085 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn << 4) | ((io_max&0xf0)<<(12-4)); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020086 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +080087 pci_write_config32(__f1_dev[i], reg+4, tempreg);
Elyes HAOUAS27e18012017-06-27 23:14:51 +020088 tempreg = 3 /*| (3 << 4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020089 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +080090 pci_write_config32(__f1_dev[i], reg, tempreg);
91}
92
93static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
94{
95 u32 i;
96 u32 tempreg;
97 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020098 tempreg = (nodeid&0xf) | (linkn << 4) | (mmio_max&0xffffff00); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020099 for (i = 0; i < nodes; i++)
zbao2c08f6a2012-07-02 15:32:58 +0800100 pci_write_config32(__f1_dev[i], reg+4, tempreg);
101 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200102 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +0800103 pci_write_config32(__f1_dev[i], reg, tempreg);
104}
105
106static device_t get_node_pci(u32 nodeid, u32 fn)
107{
zbaod4627362012-07-23 19:49:40 +0800108#if MAX_NODE_NUMS + CONFIG_CDB >= 32
109 if ((CONFIG_CDB + nodeid) < 32) {
zbao2c08f6a2012-07-02 15:32:58 +0800110 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
111 } else {
112 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
113 }
114#else
115 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
116#endif
117}
118
119static void get_fx_devs(void)
120{
121 int i;
122 for (i = 0; i < MAX_NODE_NUMS; i++) {
123 __f0_dev[i] = get_node_pci(i, 0);
124 __f1_dev[i] = get_node_pci(i, 1);
125 __f2_dev[i] = get_node_pci(i, 2);
126 __f4_dev[i] = get_node_pci(i, 4);
127 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
128 fx_devs = i+1;
129 }
130 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
131 die("Cannot find 0:0x18.[0|1]\n");
132 }
133 printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs);
134}
135
136static u32 f1_read_config32(unsigned reg)
137{
138 if (fx_devs == 0)
139 get_fx_devs();
140 return pci_read_config32(__f1_dev[0], reg);
141}
142
143static void f1_write_config32(unsigned reg, u32 value)
144{
145 int i;
146 if (fx_devs == 0)
147 get_fx_devs();
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200148 for (i = 0; i < fx_devs; i++) {
zbao2c08f6a2012-07-02 15:32:58 +0800149 device_t dev;
150 dev = __f1_dev[i];
151 if (dev && dev->enabled) {
152 pci_write_config32(dev, reg, value);
153 }
154 }
155}
156
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300157static u32 amdfam15_nodeid(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800158{
159#if MAX_NODE_NUMS == 64
160 unsigned busn;
161 busn = dev->bus->secondary;
162 if (busn != CONFIG_CBB) {
163 return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32;
164 } else {
165 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
166 }
167
168#else
169 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
170#endif
171}
172
173static void set_vga_enable_reg(u32 nodeid, u32 linkn)
174{
175 u32 val;
176
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200177 val = 1 | (nodeid << 4) | (linkn << 12);
zbao2c08f6a2012-07-02 15:32:58 +0800178 /* it will routing
179 * (1)mmio 0xa0000:0xbffff
180 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
181 */
182 f1_write_config32(0xf4, val);
183
184}
185
186/**
187 * @return
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100188 * @retval 2 resoure does not exist, usable
189 * @retval 0 resource exists, not usable
zbao2c08f6a2012-07-02 15:32:58 +0800190 * @retval 1 resource exist, resource has been allocated before
191 */
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300192static int reg_useable(unsigned reg, struct device *goal_dev, unsigned goal_nodeid,
zbao2c08f6a2012-07-02 15:32:58 +0800193 unsigned goal_link)
194{
195 struct resource *res;
196 unsigned nodeid, link = 0;
197 int result;
198 res = 0;
199 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300200 struct device *dev;
zbao2c08f6a2012-07-02 15:32:58 +0800201 dev = __f0_dev[nodeid];
202 if (!dev)
203 continue;
204 for (link = 0; !res && (link < 8); link++) {
205 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
206 }
207 }
208 result = 2;
209 if (res) {
210 result = 0;
211 if ((goal_link == (link - 1)) &&
212 (goal_nodeid == (nodeid - 1)) &&
213 (res->flags <= 1)) {
214 result = 1;
215 }
216 }
217 return result;
218}
219
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300220static struct resource *amdfam15_find_iopair(struct device *dev, unsigned nodeid, unsigned link)
zbao2c08f6a2012-07-02 15:32:58 +0800221{
222 struct resource *resource;
223 u32 free_reg, reg;
224 resource = 0;
225 free_reg = 0;
226 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
227 int result;
228 result = reg_useable(reg, dev, nodeid, link);
229 if (result == 1) {
230 /* I have been allocated this one */
231 break;
232 }
233 else if (result > 1) {
234 /* I have a free register pair */
235 free_reg = reg;
236 }
237 }
238 if (reg > 0xd8) {
239 reg = free_reg; // if no free, the free_reg still be 0
240 }
241
242 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
243
244 return resource;
245}
246
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300247static struct resource *amdfam15_find_mempair(struct device *dev, u32 nodeid, u32 link)
zbao2c08f6a2012-07-02 15:32:58 +0800248{
249 struct resource *resource;
250 u32 free_reg, reg;
251 resource = 0;
252 free_reg = 0;
253 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
254 int result;
255 result = reg_useable(reg, dev, nodeid, link);
256 if (result == 1) {
257 /* I have been allocated this one */
258 break;
259 }
260 else if (result > 1) {
261 /* I have a free register pair */
262 free_reg = reg;
263 }
264 }
265 if (reg > 0xb8) {
266 reg = free_reg;
267 }
268
269 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
270 return resource;
271}
272
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300273static void amdfam15_link_read_bases(struct device *dev, u32 nodeid, u32 link)
zbao2c08f6a2012-07-02 15:32:58 +0800274{
275 struct resource *resource;
276
277 /* Initialize the io space constraints on the current bus */
278 resource = amdfam15_find_iopair(dev, nodeid, link);
279 if (resource) {
280 u32 align;
281 align = log2(HT_IO_HOST_ALIGN);
282 resource->base = 0;
283 resource->size = 0;
284 resource->align = align;
285 resource->gran = align;
286 resource->limit = 0xffffUL;
287 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
288 }
289
290 /* Initialize the prefetchable memory constraints on the current bus */
291 resource = amdfam15_find_mempair(dev, nodeid, link);
292 if (resource) {
293 resource->base = 0;
294 resource->size = 0;
295 resource->align = log2(HT_MEM_HOST_ALIGN);
296 resource->gran = log2(HT_MEM_HOST_ALIGN);
297 resource->limit = 0xffffffffffULL;
298 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
299 resource->flags |= IORESOURCE_BRIDGE;
300 }
301
302 /* Initialize the memory constraints on the current bus */
303 resource = amdfam15_find_mempair(dev, nodeid, link);
304 if (resource) {
305 resource->base = 0;
306 resource->size = 0;
307 resource->align = log2(HT_MEM_HOST_ALIGN);
308 resource->gran = log2(HT_MEM_HOST_ALIGN);
309 resource->limit = 0xffffffffffULL;
310 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
311 }
312
313}
314
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300315static void nb_read_resources(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800316{
317 u32 nodeid;
318 struct bus *link;
319
320 nodeid = amdfam15_nodeid(dev);
321 for (link = dev->link_list; link; link = link->next) {
322 if (link->children) {
323 amdfam15_link_read_bases(dev, nodeid, link->link_num);
324 }
325 }
Steven Sherk1cbabb02013-02-01 09:22:35 -0700326
327 /*
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800328 * This MMCONF resource must be reserved in the PCI domain.
Steven Sherk1cbabb02013-02-01 09:22:35 -0700329 * It is not honored by the coreboot resource allocator if it is in
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800330 * the CPU_CLUSTER.
Steven Sherk1cbabb02013-02-01 09:22:35 -0700331 */
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200332 mmconf_resource(dev, 0xc0010058);
zbao2c08f6a2012-07-02 15:32:58 +0800333}
334
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300335static void set_resource(struct device *dev, struct resource *resource, u32 nodeid)
zbao2c08f6a2012-07-02 15:32:58 +0800336{
337 resource_t rbase, rend;
338 unsigned reg, link_num;
339 char buf[50];
340
341 /* Make certain the resource has actually been set */
342 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
343 return;
344 }
345
346 /* If I have already stored this resource don't worry about it */
347 if (resource->flags & IORESOURCE_STORED) {
348 return;
349 }
350
351 /* Only handle PCI memory and IO resources */
352 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
353 return;
354
355 /* Ensure I am actually looking at a resource of function 1 */
356 if ((resource->index & 0xffff) < 0x1000) {
357 return;
358 }
359 /* Get the base address */
360 rbase = resource->base;
361
362 /* Get the limit (rounded up) */
363 rend = resource_end(resource);
364
365 /* Get the register and link */
366 reg = resource->index & 0xfff; // 4k
367 link_num = IOINDEX_LINK(resource->index);
368
369 if (resource->flags & IORESOURCE_IO) {
370 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
371 }
372 else if (resource->flags & IORESOURCE_MEM) {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100373 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 +0800374 }
375 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200376 snprintf(buf, sizeof(buf), " <node %x link %x>",
zbao2c08f6a2012-07-02 15:32:58 +0800377 nodeid, link_num);
378 report_resource_stored(dev, resource, buf);
379}
380
381/**
382 * I tried to reuse the resource allocation code in set_resource()
383 * but it is too difficult to deal with the resource allocation magic.
384 */
385
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300386static void create_vga_resource(struct device *dev, unsigned nodeid)
zbao2c08f6a2012-07-02 15:32:58 +0800387{
388 struct bus *link;
389
390 /* find out which link the VGA card is connected,
391 * we only deal with the 'first' vga card */
392 for (link = dev->link_list; link; link = link->next) {
393 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
Martin Roth77a58b92017-06-24 14:45:48 -0600394#if IS_ENABLED(CONFIG_MULTIPLE_VGA_ADAPTERS)
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300395 extern struct device *vga_pri; // the primary vga device, defined in device.c
zbao2c08f6a2012-07-02 15:32:58 +0800396 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
397 link->secondary,link->subordinate);
398 /* We need to make sure the vga_pri is under the link */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200399 if ((vga_pri->bus->secondary >= link->secondary) &&
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300400 (vga_pri->bus->secondary <= link->subordinate))
zbao2c08f6a2012-07-02 15:32:58 +0800401#endif
402 break;
403 }
404 }
405
406 /* no VGA card installed */
407 if (link == NULL)
408 return;
409
410 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
411 set_vga_enable_reg(nodeid, sblink);
412}
413
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300414static void nb_set_resources(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800415{
416 unsigned nodeid;
417 struct bus *bus;
418 struct resource *res;
419
420 /* Find the nodeid */
421 nodeid = amdfam15_nodeid(dev);
422
423 create_vga_resource(dev, nodeid); //TODO: do we need this?
424
425 /* Set each resource we have found */
426 for (res = dev->resource_list; res; res = res->next) {
427 set_resource(dev, res, nodeid);
428 }
429
430 for (bus = dev->link_list; bus; bus = bus->next) {
431 if (bus->children) {
432 assign_resources(bus);
433 }
434 }
435}
436
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100437static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200438{
439 void *addr, *current;
440
441 /* Skip the HEST header. */
442 current = (void *)(hest + 1);
443
444 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
445 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700446 current += acpi_create_hest_error_source(hest, current, 0,
447 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200448
449 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
450 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700451 current += acpi_create_hest_error_source(hest, current, 1,
452 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200453
454 return (unsigned long)current;
455}
456
Alexander Couzens5eea4582015-04-12 22:18:55 +0200457static void northbridge_fill_ssdt_generator(device_t device)
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200458{
459 msr_t msr;
460 char pscope[] = "\\_SB.PCI0";
461
462 acpigen_write_scope(pscope);
463 msr = rdmsr(TOP_MEM);
464 acpigen_write_name_dword("TOM1", msr.lo);
465 msr = rdmsr(TOP_MEM2);
466 /*
467 * Since XP only implements parts of ACPI 2.0, we can't use a qword
468 * here.
469 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
470 * slide 22ff.
471 * Shift value right by 20 bit to make it fit into 32bit,
472 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
473 */
474 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
475 acpigen_pop_len();
476}
477
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200478static unsigned long agesa_write_acpi_tables(device_t device,
479 unsigned long current,
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200480 acpi_rsdp_t *rsdp)
481{
482 acpi_srat_t *srat;
483 acpi_slit_t *slit;
484 acpi_header_t *ssdt;
485 acpi_header_t *alib;
486 acpi_header_t *ivrs;
487 acpi_hest_t *hest;
488
489 /* HEST */
490 current = ALIGN(current, 8);
491 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100492 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200493 acpi_add_table(rsdp, (void *)current);
494 current += ((acpi_header_t *)current)->length;
495
496 current = ALIGN(current, 8);
497 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
498 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
499 if (ivrs != NULL) {
500 memcpy((void *)current, ivrs, ivrs->length);
501 ivrs = (acpi_header_t *) current;
502 current += ivrs->length;
503 acpi_add_table(rsdp, ivrs);
504 } else {
505 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
506 }
507
508 /* SRAT */
509 current = ALIGN(current, 8);
510 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
511 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
512 if (srat != NULL) {
513 memcpy((void *)current, srat, srat->header.length);
514 srat = (acpi_srat_t *) current;
515 current += srat->header.length;
516 acpi_add_table(rsdp, srat);
517 } else {
518 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
519 }
520
521 /* SLIT */
522 current = ALIGN(current, 8);
523 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
524 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
525 if (slit != NULL) {
526 memcpy((void *)current, slit, slit->header.length);
527 slit = (acpi_slit_t *) current;
528 current += slit->header.length;
529 acpi_add_table(rsdp, slit);
530 } else {
531 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
532 }
533
534 /* ALIB */
535 current = ALIGN(current, 16);
536 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
537 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
538 if (alib != NULL) {
539 memcpy((void *)current, alib, alib->length);
540 alib = (acpi_header_t *) current;
541 current += alib->length;
542 acpi_add_table(rsdp, (void *)alib);
543 }
544 else {
545 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
546 }
547
548 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
549 /* SSDT */
550 current = ALIGN(current, 16);
551 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
552 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
553 if (ssdt != NULL) {
554 memcpy((void *)current, ssdt, ssdt->length);
555 ssdt = (acpi_header_t *) current;
556 current += ssdt->length;
557 }
558 else {
559 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
560 }
561 acpi_add_table(rsdp,ssdt);
562
563 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
564
565 return current;
566}
567
568
zbao2c08f6a2012-07-02 15:32:58 +0800569static struct device_operations northbridge_operations = {
Steven Sherkf4340582013-01-29 16:13:35 -0700570 .read_resources = nb_read_resources,
571 .set_resources = nb_set_resources,
zbao2c08f6a2012-07-02 15:32:58 +0800572 .enable_resources = pci_dev_enable_resources,
Edward O'Callaghand994ef12014-11-21 02:22:33 +1100573 .init = DEVICE_NOOP,
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200574 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
575 .write_acpi_tables = agesa_write_acpi_tables,
zbao2c08f6a2012-07-02 15:32:58 +0800576 .enable = 0,
577 .ops_pci = 0,
578};
579
580static const struct pci_driver family15_northbridge __pci_driver = {
581 .ops = &northbridge_operations,
582 .vendor = PCI_VENDOR_ID_AMD,
Marshall Dawson463f46e2016-10-14 20:46:08 -0600583 .device = PCI_DEVICE_ID_AMD_15H_MODEL_101F_NB_HT,
zbao2c08f6a2012-07-02 15:32:58 +0800584};
585
586static const struct pci_driver family10_northbridge __pci_driver = {
587 .ops = &northbridge_operations,
588 .vendor = PCI_VENDOR_ID_AMD,
589 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
590};
591
592struct chip_operations northbridge_amd_agesa_family15tn_ops = {
593 CHIP_NAME("AMD FAM15 Northbridge")
594 .enable_dev = 0,
595};
596
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300597static void domain_read_resources(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800598{
599 unsigned reg;
600
601 /* Find the already assigned resource pairs */
602 get_fx_devs();
603 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
604 u32 base, limit;
605 base = f1_read_config32(reg);
606 limit = f1_read_config32(reg + 0x04);
607 /* Is this register allocated? */
608 if ((base & 3) != 0) {
609 unsigned nodeid, reg_link;
610 device_t reg_dev;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200611 if (reg < 0xc0) { // mmio
zbao2c08f6a2012-07-02 15:32:58 +0800612 nodeid = (limit & 0xf) + (base&0x30);
613 } else { // io
614 nodeid = (limit & 0xf) + ((base>>4)&0x30);
615 }
616 reg_link = (limit >> 4) & 7;
617 reg_dev = __f0_dev[nodeid];
618 if (reg_dev) {
619 /* Reserve the resource */
620 struct resource *res;
621 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
622 if (res) {
623 res->flags = 1;
624 }
625 }
626 }
627 }
628 /* FIXME: do we need to check extend conf space?
629 I don't believe that much preset value */
630
zbao2c08f6a2012-07-02 15:32:58 +0800631 pci_domain_read_resources(dev);
zbao2c08f6a2012-07-02 15:32:58 +0800632}
633
zbao2c08f6a2012-07-02 15:32:58 +0800634static void domain_enable_resources(device_t dev)
635{
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200636#if IS_ENABLED(CONFIG_AGESA_LEGACY_WRAPPER)
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +0300637 if (acpi_is_wakeup_s3())
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300638 agesawrapper_fchs3laterestore();
zbao2c08f6a2012-07-02 15:32:58 +0800639
640 /* Must be called after PCI enumeration and resource allocation */
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300641 if (!acpi_is_wakeup_s3()) {
642 /* Enable MMIO on AMD CPU Address Map Controller */
Kyösti Mälkki48518f02014-11-25 14:20:57 +0200643 amd_initcpuio();
zbao2c08f6a2012-07-02 15:32:58 +0800644
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300645 agesawrapper_amdinitmid();
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300646 }
Mike Loptiene133aab2013-01-30 16:00:43 -0700647 printk(BIOS_DEBUG, " ader - leaving %s.\n", __func__);
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200648#endif
zbao2c08f6a2012-07-02 15:32:58 +0800649}
650
651#if CONFIG_HW_MEM_HOLE_SIZEK != 0
652struct hw_mem_hole_info {
653 unsigned hole_startk;
654 int node_id;
655};
656static struct hw_mem_hole_info get_hw_mem_hole_info(void)
657{
658 struct hw_mem_hole_info mem_hole;
659 int i;
660 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
661 mem_hole.node_id = -1;
662 for (i = 0; i < node_nums; i++) {
663 dram_base_mask_t d;
664 u32 hole;
665 d = get_dram_base_mask(i);
666 if (!(d.mask & 1)) continue; // no memory on this node
667 hole = pci_read_config32(__f1_dev[i], 0xf0);
668 if (hole & 1) { // we find the hole
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200669 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
zbao2c08f6a2012-07-02 15:32:58 +0800670 mem_hole.node_id = i; // record the node No with hole
671 break; // only one hole
672 }
673 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300674
675 /* We need to double check if there is special set on base reg and limit reg
676 * are not continuous instead of hole, it will find out its hole_startk.
677 */
zbao2c08f6a2012-07-02 15:32:58 +0800678 if (mem_hole.node_id == -1) {
679 resource_t limitk_pri = 0;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200680 for (i = 0; i < node_nums; i++) {
zbao2c08f6a2012-07-02 15:32:58 +0800681 dram_base_mask_t d;
682 resource_t base_k, limit_k;
683 d = get_dram_base_mask(i);
684 if (!(d.base & 1)) continue;
685 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
686 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
687 if (limitk_pri != base_k) { // we find the hole
688 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
689 mem_hole.node_id = i;
690 break; //only one hole
691 }
zbao15dc3cc2012-08-03 15:56:21 +0800692 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800693 limitk_pri = limit_k;
694 }
695 }
696 return mem_hole;
697}
698#endif
699
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300700static void domain_set_resources(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800701{
zbao2c08f6a2012-07-02 15:32:58 +0800702 unsigned long mmio_basek;
703 u32 pci_tolm;
704 int i, idx;
705 struct bus *link;
706#if CONFIG_HW_MEM_HOLE_SIZEK != 0
707 struct hw_mem_hole_info mem_hole;
708 u32 reset_memhole = 1;
709#endif
710
zbao2c08f6a2012-07-02 15:32:58 +0800711 pci_tolm = 0xffffffffUL;
712 for (link = dev->link_list; link; link = link->next) {
713 pci_tolm = find_pci_tolm(link);
714 }
715
716 // FIXME handle interleaved nodes. If you fix this here, please fix
717 // amdk8, too.
718 mmio_basek = pci_tolm >> 10;
719 /* Round mmio_basek to something the processor can support */
720 mmio_basek &= ~((1 << 6) -1);
721
722 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
723 // MMIO hole. If you fix this here, please fix amdk8, too.
724 /* Round the mmio hole to 64M */
725 mmio_basek &= ~((64*1024) - 1);
726
727#if CONFIG_HW_MEM_HOLE_SIZEK != 0
728 /* if the hw mem hole is already set in raminit stage, here we will compare
729 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
730 * use hole_basek as mmio_basek and we don't need to reset hole.
731 * otherwise We reset the hole to the mmio_basek
732 */
733
734 mem_hole = get_hw_mem_hole_info();
735
736 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
737 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
738 mmio_basek = mem_hole.hole_startk;
739 reset_memhole = 0;
740 }
741#endif
742
743 idx = 0x10;
744 for (i = 0; i < node_nums; i++) {
745 dram_base_mask_t d;
746 resource_t basek, limitk, sizek; // 4 1T
747
748 d = get_dram_base_mask(i);
749
750 if (!(d.mask & 1)) continue;
751 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100752 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800753
754 sizek = limitk - basek;
755
756 /* see if we need a hole from 0xa0000 to 0xbffff */
757 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
758 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
759 idx += 0x10;
760 basek = (8*64)+(16*16);
761 sizek = limitk - ((8*64)+(16*16));
762
763 }
764
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300765 /* split the region to accommodate pci memory space */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200766 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
zbao2c08f6a2012-07-02 15:32:58 +0800767 if (basek <= mmio_basek) {
768 unsigned pre_sizek;
769 pre_sizek = mmio_basek - basek;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200770 if (pre_sizek > 0) {
zbao2c08f6a2012-07-02 15:32:58 +0800771 ram_resource(dev, (idx | i), basek, pre_sizek);
772 idx += 0x10;
773 sizek -= pre_sizek;
zbao2c08f6a2012-07-02 15:32:58 +0800774 }
775 basek = mmio_basek;
776 }
777 if ((basek + sizek) <= 4*1024*1024) {
778 sizek = 0;
779 }
780 else {
Siyuan Wang29840e22013-06-04 19:56:22 +0800781 uint64_t topmem2 = bsp_topmem2();
zbao2c08f6a2012-07-02 15:32:58 +0800782 basek = 4*1024*1024;
Siyuan Wang29840e22013-06-04 19:56:22 +0800783 sizek = topmem2/1024 - basek;
zbao2c08f6a2012-07-02 15:32:58 +0800784 }
785 }
786
zbao2c08f6a2012-07-02 15:32:58 +0800787 ram_resource(dev, (idx | i), basek, sizek);
788 idx += 0x10;
zbao2c08f6a2012-07-02 15:32:58 +0800789 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
790 i, mmio_basek, basek, limitk);
zbao2c08f6a2012-07-02 15:32:58 +0800791 }
792
Kyösti Mälkki61be3602017-04-15 20:07:53 +0300793 add_uma_resource_below_tolm(dev, 7);
zbao2c08f6a2012-07-02 15:32:58 +0800794
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200795 for (link = dev->link_list; link; link = link->next) {
zbao2c08f6a2012-07-02 15:32:58 +0800796 if (link->children) {
797 assign_resources(link);
798 }
799 }
800}
801
802static struct device_operations pci_domain_ops = {
803 .read_resources = domain_read_resources,
804 .set_resources = domain_set_resources,
805 .enable_resources = domain_enable_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100806 .init = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +0800807 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki872c9222013-07-03 09:44:28 +0300808 .ops_pci_bus = pci_bus_default_ops,
zbao2c08f6a2012-07-02 15:32:58 +0800809};
810
811static void sysconf_init(device_t dev) // first node
812{
813 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
814 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
815}
816
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300817static void add_more_links(struct device *dev, unsigned total_links)
zbao2c08f6a2012-07-02 15:32:58 +0800818{
819 struct bus *link, *last = NULL;
820 int link_num;
821
822 for (link = dev->link_list; link; link = link->next)
823 last = link;
824
825 if (last) {
826 int links = total_links - last->link_num;
827 link_num = last->link_num;
828 if (links > 0) {
829 link = malloc(links*sizeof(*link));
830 if (!link)
831 die("Couldn't allocate more links!\n");
832 memset(link, 0, links*sizeof(*link));
833 last->next = link;
834 }
835 }
836 else {
837 link_num = -1;
838 link = malloc(total_links*sizeof(*link));
839 memset(link, 0, total_links*sizeof(*link));
840 dev->link_list = link;
841 }
842
843 for (link_num = link_num + 1; link_num < total_links; link_num++) {
844 link->link_num = link_num;
845 link->dev = dev;
846 link->next = link + 1;
847 last = link;
848 link = link->next;
849 }
850 last->next = NULL;
851}
852
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200853static void cpu_bus_scan(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800854{
855 struct bus *cpu_bus;
856 device_t dev_mc;
857#if CONFIG_CBB
858 device_t pci_domain;
859#endif
860 int i,j;
861 int coreid_bits;
862 int core_max = 0;
863 unsigned ApicIdCoreIdSize;
864 unsigned core_nums;
865 int siblings = 0;
866 unsigned int family;
867
868#if CONFIG_CBB
869 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
870 if (dev_mc && dev_mc->bus) {
871 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
872 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800873 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800874 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
875 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
876 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
877 } else {
878 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
879 }
880 printk(BIOS_DEBUG, "\n");
881 }
882 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
883 if (!dev_mc) {
884 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
885 if (dev_mc && dev_mc->bus) {
886 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
887 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800888 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800889 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
890 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
891 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
892 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
893 while (dev_mc) {
894 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
895 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
896 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
897 dev_mc = dev_mc->sibling;
898 }
899 }
900 }
901 }
902 }
903#endif
904 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
905 if (!dev_mc) {
906 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
907 die("");
908 }
909 sysconf_init(dev_mc);
910#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200911 if (node_nums > 32) { // need to put node 32 to node 63 to bus 0xfe
zbao2c08f6a2012-07-02 15:32:58 +0800912 if (pci_domain->link_list && !pci_domain->link_list->next) {
913 struct bus *new_link = new_link(pci_domain);
914 pci_domain->link_list->next = new_link;
915 new_link->link_num = 1;
916 new_link->dev = pci_domain;
917 new_link->children = 0;
918 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
919 }
920 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
921 }
922#endif
923
924 /* Get Max Number of cores(MNC) */
925 coreid_bits = (cpuid_ecx(AMD_CPUID_ASIZE_PCCOUNT) & 0x0000F000) >> 12;
926 core_max = 1 << (coreid_bits & 0x000F); //mnc
927
928 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
929 if (ApicIdCoreIdSize) {
930 core_nums = (1 << ApicIdCoreIdSize) - 1;
931 } else {
932 core_nums = 3; //quad core
933 }
934
935 /* Find which cpus are present */
936 cpu_bus = dev->link_list;
937 for (i = 0; i < node_nums; i++) {
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300938 device_t cdb_dev;
zbao2c08f6a2012-07-02 15:32:58 +0800939 unsigned busn, devn;
940 struct bus *pbus;
941
942 busn = CONFIG_CBB;
943 devn = CONFIG_CDB + i;
944 pbus = dev_mc->bus;
945#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
946 if (i >= 32) {
947 busn--;
948 devn -= 32;
949 pbus = pci_domain->link_list->next;
950 }
951#endif
952
953 /* Find the cpu's pci device */
954 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
955 if (!cdb_dev) {
956 /* If I am probing things in a weird order
957 * ensure all of the cpu's pci devices are found.
958 */
959 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200960 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
zbao2c08f6a2012-07-02 15:32:58 +0800961 cdb_dev = pci_probe_dev(NULL, pbus,
962 PCI_DEVFN(devn, fn));
963 }
964 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
965 } else {
966 /* Ok, We need to set the links for that device.
967 * otherwise the device under it will not be scanned
968 */
Kyösti Mälkki2a2d6132015-02-04 13:25:37 +0200969 add_more_links(cdb_dev, 4);
zbao2c08f6a2012-07-02 15:32:58 +0800970 }
971
972 family = cpuid_eax(1);
973 family = (family >> 20) & 0xFF;
974 if (family == 1) { //f10
975 u32 dword;
976 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
977 dword = pci_read_config32(cdb_dev, 0xe8);
978 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
979 } else if (family == 6) {//f15
980 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
981 if (cdb_dev && cdb_dev->enabled) {
982 siblings = pci_read_config32(cdb_dev, 0x84);
983 siblings &= 0xFF;
984 }
985 } else {
986 siblings = 0; //default one core
987 }
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300988 int enable_node = cdb_dev && cdb_dev->enabled;
zbao2c08f6a2012-07-02 15:32:58 +0800989 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
990 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
991
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200992 for (j = 0; j <= siblings; j++) {
zbao2c08f6a2012-07-02 15:32:58 +0800993 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
994 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
995 u32 lapicid_start = 0;
996
zbao2c08f6a2012-07-02 15:32:58 +0800997 /*
998 * APIC ID calucation is tightly coupled with AGESA v5 code.
999 * This calculation MUST match the assignment calculation done
1000 * in LocalApicInitializationAtEarly() function.
1001 * And reference GetLocalApicIdForCore()
1002 *
1003 * Apply apic enumeration rules
1004 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1005 * put the local-APICs at m..z
1006 *
1007 * This is needed because many IO-APIC devices only have 4 bits
1008 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001009 */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001010
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001011 u8 plat_num_io_apics = 3; /* FIXME */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001012
1013 if ((node_nums * core_max) + plat_num_io_apics >= 0x10) {
1014 lapicid_start = (plat_num_io_apics - 1) / core_max;
zbao2c08f6a2012-07-02 15:32:58 +08001015 lapicid_start = (lapicid_start + 1) * core_max;
1016 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
1017 }
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001018 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
zbao2c08f6a2012-07-02 15:32:58 +08001019 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001020 i, j, apic_id);
zbao2c08f6a2012-07-02 15:32:58 +08001021
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001022 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1023 if (cpu)
1024 amd_cpu_topology(cpu, i, j);
zbao2c08f6a2012-07-02 15:32:58 +08001025 } //j
1026 }
zbao2c08f6a2012-07-02 15:32:58 +08001027}
1028
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +03001029static void cpu_bus_init(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +08001030{
1031 initialize_cpus(dev->link_list);
1032}
1033
zbao2c08f6a2012-07-02 15:32:58 +08001034static struct device_operations cpu_bus_ops = {
Edward O'Callaghan2837ab22014-11-06 08:57:40 +11001035 .read_resources = DEVICE_NOOP,
1036 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001037 .enable_resources = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +08001038 .init = cpu_bus_init,
1039 .scan_bus = cpu_bus_scan,
1040};
1041
1042static void root_complex_enable_dev(struct device *dev)
1043{
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001044 static int done = 0;
1045
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001046 if (!done) {
1047 setup_bsp_ramtop();
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001048 done = 1;
1049 }
1050
zbao2c08f6a2012-07-02 15:32:58 +08001051 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -08001052 if (dev->path.type == DEVICE_PATH_DOMAIN) {
zbao2c08f6a2012-07-02 15:32:58 +08001053 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -08001054 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
zbao2c08f6a2012-07-02 15:32:58 +08001055 dev->ops = &cpu_bus_ops;
1056 }
1057}
1058
1059struct chip_operations northbridge_amd_agesa_family15tn_root_complex_ops = {
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +03001060 CHIP_NAME("AMD Family 15tn Root Complex")
zbao2c08f6a2012-07-02 15:32:58 +08001061 .enable_dev = root_complex_enable_dev,
1062};
Dave Frodincbf3d402012-12-05 08:20:12 -07001063
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001064/*********************************************************************
1065 * Change the vendor / device IDs to match the generic VBIOS header. *
1066 *********************************************************************/
Dave Frodincbf3d402012-12-05 08:20:12 -07001067u32 map_oprom_vendev(u32 vendev)
1068{
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001069 u32 new_vendev = vendev;
Dave Frodincbf3d402012-12-05 08:20:12 -07001070
1071 switch(vendev) {
Bruce Griffith42e11f52013-07-08 18:19:08 -06001072 case 0x10029900: /* AMD Radeon HD 7660G (Trinity) */
1073 case 0x10029901: /* AMD Radeon HD 7660D (Trinity) */
1074 case 0x10029903: /* AMD Radeon HD 7640G (Trinity) */
1075 case 0x10029904: /* AMD Radeon HD 7560D (Trinity) */
1076 case 0x10029907: /* AMD Radeon HD 7620G (Trinity) */
1077 case 0x10029908: /* AMD Radeon HD 7600G (Trinity) */
1078 case 0x1002990A: /* AMD Radeon HD 7500G (Trinity) */
1079 case 0x1002990B: /* AMD Radeon HD 8650G (Richland) */
1080 case 0x1002990C: /* AMD Radeon HD 8670D (Richland) */
1081 case 0x1002990D: /* AMD Radeon HD 8550G (Richland) */
1082 case 0x1002990E: /* AMD Radeon HD 8570D (Richland) */
1083 case 0x1002990F: /* AMD Radeon HD 8610G (Richland) */
1084 case 0x10029910: /* AMD Radeon HD 7660G (Trinity) */
1085 case 0x10029913: /* AMD Radeon HD 7640G (Trinity) */
1086 case 0x10029917: /* AMD Radeon HD 7620G (Trinity) */
1087 case 0x10029918: /* AMD Radeon HD 7600G (Trinity) */
1088 case 0x10029919: /* AMD Radeon HD 7500G (Trinity) */
1089 case 0x10029990: /* AMD Radeon HD 7520G (Trinity) */
1090 case 0x10029991: /* AMD Radeon HD 7540D (Trinity) */
1091 case 0x10029992: /* AMD Radeon HD 7420G (Trinity) */
1092 case 0x10029993: /* AMD Radeon HD 7480D (Trinity) */
1093 case 0x10029994: /* AMD Radeon HD 7400G (Trinity) */
1094 case 0x10029995: /* AMD Radeon HD 8450G (Richland) */
1095 case 0x10029996: /* AMD Radeon HD 8470D (Richland) */
1096 case 0x10029997: /* AMD Radeon HD 8350G (Richland) */
1097 case 0x10029998: /* AMD Radeon HD 8370D (Richland) */
1098 case 0x10029999: /* AMD Radeon HD 8510G (Richland) */
1099 case 0x1002999A: /* AMD Radeon HD 8410G (Richland) */
1100 case 0x1002999B: /* AMD Radeon HD 8310G (Richland) */
1101 case 0x1002999C: /* AMD Radeon HD 8650D (Richland) */
1102 case 0x1002999D: /* AMD Radeon HD 8550D (Richland) */
1103 case 0x100299A0: /* AMD Radeon HD 7520G (Trinity) */
1104 case 0x100299A2: /* AMD Radeon HD 7420G (Trinity) */
1105 case 0x100299A4: /* AMD Radeon HD 7400G (Trinity) */
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001106 new_vendev = 0x10029901;
Dave Frodincbf3d402012-12-05 08:20:12 -07001107 break;
1108 }
1109
1110 return new_vendev;
1111}