blob: 44f49ea094e421987ca7b78fcbd98e403888a050 [file] [log] [blame]
Siyuan Wang3e32cc02013-07-09 17:16:20 +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.
Siyuan Wang3e32cc02013-07-09 17:16:20 +080014 */
15
16#include <console/console.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020017#include <device/pci_ops.h>
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +030018#include <arch/acpi.h>
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +020019#include <arch/acpigen.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +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>
27#include <lib.h>
28#include <cpu/cpu.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080029#include <cpu/x86/lapic.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +020030#include <cpu/amd/msr.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080031#include <cpu/amd/mtrr.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080032#include <Porting.h>
33#include <AGESA.h>
34#include <Options.h>
35#include <Topology.h>
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +020036#include <northbridge/amd/agesa/nb_common.h>
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020037#include <northbridge/amd/agesa/state_machine.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020038#include <northbridge/amd/agesa/agesa_helper.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080039
Kyösti Mälkki113f6702018-05-20 20:12:32 +030040#define MAX_NODE_NUMS MAX_NODES
Siyuan Wang3e32cc02013-07-09 17:16:20 +080041
Siyuan Wang3e32cc02013-07-09 17:16:20 +080042typedef struct dram_base_mask {
43 u32 base; //[47:27] at [28:8]
44 u32 mask; //[47:27] at [28:8] and enable at bit 0
45} dram_base_mask_t;
46
47static unsigned node_nums;
48static unsigned sblink;
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030049static struct device *__f0_dev[MAX_NODE_NUMS];
50static struct device *__f1_dev[MAX_NODE_NUMS];
51static struct device *__f2_dev[MAX_NODE_NUMS];
52static struct device *__f4_dev[MAX_NODE_NUMS];
Siyuan Wang3e32cc02013-07-09 17:16:20 +080053static unsigned fx_devs = 0;
54
55static dram_base_mask_t get_dram_base_mask(u32 nodeid)
56{
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030057 struct device *dev;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080058 dram_base_mask_t d;
59 dev = __f1_dev[0];
60 u32 temp;
61 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
62 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
63 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020064 d.mask |= temp << 21;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080065 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
66 d.mask |= (temp & 1); // enable bit
67 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
68 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020069 d.base |= temp << 21;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080070 return d;
71}
72
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030073static void set_io_addr_reg(struct device *dev, u32 nodeid, u32 linkn, u32 reg,
Siyuan Wang3e32cc02013-07-09 17:16:20 +080074 u32 io_min, u32 io_max)
75{
76 u32 i;
77 u32 tempreg;
78 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020079 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn << 4) | ((io_max&0xf0)<<(12-4)); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020080 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080081 pci_write_config32(__f1_dev[i], reg+4, tempreg);
Elyes HAOUAS27e18012017-06-27 23:14:51 +020082 tempreg = 3 /*| (3 << 4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020083 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080084 pci_write_config32(__f1_dev[i], reg, tempreg);
85}
86
87static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
88{
89 u32 i;
90 u32 tempreg;
91 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020092 tempreg = (nodeid&0xf) | (linkn << 4) | (mmio_max&0xffffff00); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020093 for (i = 0; i < nodes; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080094 pci_write_config32(__f1_dev[i], reg+4, tempreg);
95 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020096 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080097 pci_write_config32(__f1_dev[i], reg, tempreg);
98}
99
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300100static struct device *get_node_pci(u32 nodeid, u32 fn)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800101{
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200102 return pcidev_on_root(DEV_CDB + nodeid, fn);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800103}
104
105static void get_fx_devs(void)
106{
107 int i;
108 for (i = 0; i < MAX_NODE_NUMS; i++) {
109 __f0_dev[i] = get_node_pci(i, 0);
110 __f1_dev[i] = get_node_pci(i, 1);
111 __f2_dev[i] = get_node_pci(i, 2);
112 __f4_dev[i] = get_node_pci(i, 4);
113 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
114 fx_devs = i+1;
115 }
116 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
117 die("Cannot find 0:0x18.[0|1]\n");
118 }
119 printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs);
120}
121
122static u32 f1_read_config32(unsigned reg)
123{
124 if (fx_devs == 0)
125 get_fx_devs();
126 return pci_read_config32(__f1_dev[0], reg);
127}
128
129static void f1_write_config32(unsigned reg, u32 value)
130{
131 int i;
132 if (fx_devs == 0)
133 get_fx_devs();
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200134 for (i = 0; i < fx_devs; i++) {
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300135 struct device *dev;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800136 dev = __f1_dev[i];
137 if (dev && dev->enabled) {
138 pci_write_config32(dev, reg, value);
139 }
140 }
141}
142
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300143static u32 amdfam16_nodeid(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800144{
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200145 return (dev->path.pci.devfn >> 3) - DEV_CDB;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800146}
147
148static void set_vga_enable_reg(u32 nodeid, u32 linkn)
149{
150 u32 val;
151
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200152 val = 1 | (nodeid << 4) | (linkn << 12);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800153 /* it will routing
154 * (1)mmio 0xa0000:0xbffff
155 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
156 */
157 f1_write_config32(0xf4, val);
158
159}
160
161/**
162 * @return
163 * @retval 2 resoure does not exist, usable
164 * @retval 0 resource exists, not usable
165 * @retval 1 resource exist, resource has been allocated before
166 */
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300167static int reg_useable(unsigned reg, struct device *goal_dev, unsigned goal_nodeid,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800168 unsigned goal_link)
169{
170 struct resource *res;
171 unsigned nodeid, link = 0;
172 int result;
173 res = 0;
174 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300175 struct device *dev;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800176 dev = __f0_dev[nodeid];
177 if (!dev)
178 continue;
179 for (link = 0; !res && (link < 8); link++) {
180 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
181 }
182 }
183 result = 2;
184 if (res) {
185 result = 0;
186 if ((goal_link == (link - 1)) &&
187 (goal_nodeid == (nodeid - 1)) &&
188 (res->flags <= 1)) {
189 result = 1;
190 }
191 }
192 return result;
193}
194
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300195static struct resource *amdfam16_find_iopair(struct device *dev, unsigned nodeid, unsigned link)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800196{
197 struct resource *resource;
198 u32 free_reg, reg;
199 resource = 0;
200 free_reg = 0;
201 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
202 int result;
203 result = reg_useable(reg, dev, nodeid, link);
204 if (result == 1) {
205 /* I have been allocated this one */
206 break;
207 }
208 else if (result > 1) {
209 /* I have a free register pair */
210 free_reg = reg;
211 }
212 }
213 if (reg > 0xd8) {
214 reg = free_reg; // if no free, the free_reg still be 0
215 }
216
217 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
218
219 return resource;
220}
221
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300222static struct resource *amdfam16_find_mempair(struct device *dev, u32 nodeid, u32 link)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800223{
224 struct resource *resource;
225 u32 free_reg, reg;
226 resource = 0;
227 free_reg = 0;
228 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
229 int result;
230 result = reg_useable(reg, dev, nodeid, link);
231 if (result == 1) {
232 /* I have been allocated this one */
233 break;
234 }
235 else if (result > 1) {
236 /* I have a free register pair */
237 free_reg = reg;
238 }
239 }
240 if (reg > 0xb8) {
241 reg = free_reg;
242 }
243
244 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
245 return resource;
246}
247
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300248static void amdfam16_link_read_bases(struct device *dev, u32 nodeid, u32 link)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800249{
250 struct resource *resource;
251
252 /* Initialize the io space constraints on the current bus */
253 resource = amdfam16_find_iopair(dev, nodeid, link);
254 if (resource) {
255 u32 align;
256 align = log2(HT_IO_HOST_ALIGN);
257 resource->base = 0;
258 resource->size = 0;
259 resource->align = align;
260 resource->gran = align;
261 resource->limit = 0xffffUL;
262 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
263 }
264
265 /* Initialize the prefetchable memory constraints on the current bus */
266 resource = amdfam16_find_mempair(dev, nodeid, link);
267 if (resource) {
268 resource->base = 0;
269 resource->size = 0;
270 resource->align = log2(HT_MEM_HOST_ALIGN);
271 resource->gran = log2(HT_MEM_HOST_ALIGN);
272 resource->limit = 0xffffffffffULL;
273 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
274 resource->flags |= IORESOURCE_BRIDGE;
275 }
276
277 /* Initialize the memory constraints on the current bus */
278 resource = amdfam16_find_mempair(dev, nodeid, link);
279 if (resource) {
280 resource->base = 0;
281 resource->size = 0;
282 resource->align = log2(HT_MEM_HOST_ALIGN);
283 resource->gran = log2(HT_MEM_HOST_ALIGN);
284 resource->limit = 0xffffffffffULL;
285 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
286 }
287
288}
289
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300290static void read_resources(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800291{
292 u32 nodeid;
293 struct bus *link;
294
295 nodeid = amdfam16_nodeid(dev);
296 for (link = dev->link_list; link; link = link->next) {
297 if (link->children) {
298 amdfam16_link_read_bases(dev, nodeid, link->link_num);
299 }
300 }
Edward O'Callaghan66c65322014-11-21 01:43:38 +1100301
302 /*
303 * This MMCONF resource must be reserved in the PCI_DOMAIN.
304 * It is not honored by the coreboot resource allocator if it is in
305 * the APIC_CLUSTER.
306 */
Elyes HAOUAS400ce552018-10-12 10:54:30 +0200307 mmconf_resource(dev, MMIO_CONF_BASE);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800308}
309
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300310static void set_resource(struct device *dev, struct resource *resource, u32 nodeid)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800311{
312 resource_t rbase, rend;
313 unsigned reg, link_num;
314 char buf[50];
315
316 /* Make certain the resource has actually been set */
317 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
318 return;
319 }
320
321 /* If I have already stored this resource don't worry about it */
322 if (resource->flags & IORESOURCE_STORED) {
323 return;
324 }
325
326 /* Only handle PCI memory and IO resources */
327 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
328 return;
329
330 /* Ensure I am actually looking at a resource of function 1 */
331 if ((resource->index & 0xffff) < 0x1000) {
332 return;
333 }
334 /* Get the base address */
335 rbase = resource->base;
336
337 /* Get the limit (rounded up) */
338 rend = resource_end(resource);
339
340 /* Get the register and link */
341 reg = resource->index & 0xfff; // 4k
342 link_num = IOINDEX_LINK(resource->index);
343
344 if (resource->flags & IORESOURCE_IO) {
345 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
346 }
347 else if (resource->flags & IORESOURCE_MEM) {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100348 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8, node_nums);// [39:8]
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800349 }
350 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200351 snprintf(buf, sizeof(buf), " <node %x link %x>",
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800352 nodeid, link_num);
353 report_resource_stored(dev, resource, buf);
354}
355
356/**
357 * I tried to reuse the resource allocation code in set_resource()
358 * but it is too difficult to deal with the resource allocation magic.
359 */
360
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300361static void create_vga_resource(struct device *dev, unsigned nodeid)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800362{
363 struct bus *link;
364
365 /* find out which link the VGA card is connected,
366 * we only deal with the 'first' vga card */
367 for (link = dev->link_list; link; link = link->next) {
368 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800369#if CONFIG(MULTIPLE_VGA_ADAPTERS)
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300370 extern struct device *vga_pri; // the primary vga device, defined in device.c
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800371 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
372 link->secondary,link->subordinate);
373 /* We need to make sure the vga_pri is under the link */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200374 if ((vga_pri->bus->secondary >= link->secondary) &&
375 (vga_pri->bus->secondary <= link->subordinate))
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800376#endif
377 break;
378 }
379 }
380
381 /* no VGA card installed */
382 if (link == NULL)
383 return;
384
385 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
386 set_vga_enable_reg(nodeid, sblink);
387}
388
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300389static void set_resources(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800390{
391 unsigned nodeid;
392 struct bus *bus;
393 struct resource *res;
394
395 /* Find the nodeid */
396 nodeid = amdfam16_nodeid(dev);
397
398 create_vga_resource(dev, nodeid); //TODO: do we need this?
399
400 /* Set each resource we have found */
401 for (res = dev->resource_list; res; res = res->next) {
402 set_resource(dev, res, nodeid);
403 }
404
405 for (bus = dev->link_list; bus; bus = bus->next) {
406 if (bus->children) {
407 assign_resources(bus);
408 }
409 }
410}
411
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200412
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100413static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200414{
415 void *addr, *current;
416
417 /* Skip the HEST header. */
418 current = (void *)(hest + 1);
419
420 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
421 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700422 current += acpi_create_hest_error_source(hest, current, 0,
423 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200424
425 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
426 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700427 current += acpi_create_hest_error_source(hest, current, 1,
428 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200429
430 return (unsigned long)current;
431}
432
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300433static void northbridge_fill_ssdt_generator(struct device *device)
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200434{
435 msr_t msr;
436 char pscope[] = "\\_SB.PCI0";
437
438 acpigen_write_scope(pscope);
439 msr = rdmsr(TOP_MEM);
440 acpigen_write_name_dword("TOM1", msr.lo);
441 msr = rdmsr(TOP_MEM2);
442 /*
443 * Since XP only implements parts of ACPI 2.0, we can't use a qword
444 * here.
445 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
446 * slide 22ff.
447 * Shift value right by 20 bit to make it fit into 32bit,
448 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
449 */
450 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
451 acpigen_pop_len();
452}
453
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300454static unsigned long agesa_write_acpi_tables(struct device *device,
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200455 unsigned long current,
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200456 acpi_rsdp_t *rsdp)
457{
458 acpi_srat_t *srat;
459 acpi_slit_t *slit;
460 acpi_header_t *ssdt;
461 acpi_header_t *alib;
462 acpi_header_t *ivrs;
463 acpi_hest_t *hest;
464
465 /* HEST */
466 current = ALIGN(current, 8);
467 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100468 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200469 acpi_add_table(rsdp, (void *)current);
470 current += ((acpi_header_t *)current)->length;
471
472 current = ALIGN(current, 8);
473 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
474 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
475 if (ivrs != NULL) {
476 memcpy((void *)current, ivrs, ivrs->length);
477 ivrs = (acpi_header_t *) current;
478 current += ivrs->length;
479 acpi_add_table(rsdp, ivrs);
480 } else {
481 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
482 }
483
484 /* SRAT */
485 current = ALIGN(current, 8);
486 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
487 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
488 if (srat != NULL) {
489 memcpy((void *)current, srat, srat->header.length);
490 srat = (acpi_srat_t *) current;
491 current += srat->header.length;
492 acpi_add_table(rsdp, srat);
493 } else {
494 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
495 }
496
497 /* SLIT */
498 current = ALIGN(current, 8);
499 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
500 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
501 if (slit != NULL) {
502 memcpy((void *)current, slit, slit->header.length);
503 slit = (acpi_slit_t *) current;
504 current += slit->header.length;
505 acpi_add_table(rsdp, slit);
506 } else {
507 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
508 }
509
510 /* ALIB */
511 current = ALIGN(current, 16);
512 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
513 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
514 if (alib != NULL) {
515 memcpy((void *)current, alib, alib->length);
516 alib = (acpi_header_t *) current;
517 current += alib->length;
518 acpi_add_table(rsdp, (void *)alib);
519 }
520 else {
521 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
522 }
523
524 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
525 /* SSDT */
526 current = ALIGN(current, 16);
527 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
528 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
529 if (ssdt != NULL) {
530 memcpy((void *)current, ssdt, ssdt->length);
531 ssdt = (acpi_header_t *) current;
532 current += ssdt->length;
533 }
534 else {
535 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
536 }
537 acpi_add_table(rsdp,ssdt);
538
539 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
540
541 return current;
542}
543
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800544static struct device_operations northbridge_operations = {
545 .read_resources = read_resources,
546 .set_resources = set_resources,
547 .enable_resources = pci_dev_enable_resources,
Edward O'Callaghand994ef12014-11-21 02:22:33 +1100548 .init = DEVICE_NOOP,
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200549 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
550 .write_acpi_tables = agesa_write_acpi_tables,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800551 .enable = 0,
552 .ops_pci = 0,
553};
554
555static const struct pci_driver family16_northbridge __pci_driver = {
556 .ops = &northbridge_operations,
557 .vendor = PCI_VENDOR_ID_AMD,
558 .device = PCI_DEVICE_ID_AMD_16H_MODEL_000F_NB_HT,
559};
560
561static const struct pci_driver family10_northbridge __pci_driver = {
562 .ops = &northbridge_operations,
563 .vendor = PCI_VENDOR_ID_AMD,
564 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
565};
566
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200567static void fam16_finalize(void *chip_info)
568{
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300569 struct device *dev;
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200570 u32 value;
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300571 dev = pcidev_on_root(0, 0); /* clear IoapicSbFeatureEn */
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200572 pci_write_config32(dev, 0xF8, 0);
573 pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */
574
575 /* disable No Snoop */
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300576 dev = pcidev_on_root(1, 1);
Kyösti Mälkki69f6fd42019-01-21 14:19:01 +0200577 if (dev != NULL) {
578 value = pci_read_config32(dev, 0x60);
579 value &= ~(1 << 11);
580 pci_write_config32(dev, 0x60, value);
581 }
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200582}
583
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800584struct chip_operations northbridge_amd_agesa_family16kb_ops = {
585 CHIP_NAME("AMD FAM16 Northbridge")
586 .enable_dev = 0,
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200587 .final = fam16_finalize,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800588};
589
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300590static void domain_read_resources(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800591{
592 unsigned reg;
593
594 /* Find the already assigned resource pairs */
595 get_fx_devs();
596 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
597 u32 base, limit;
598 base = f1_read_config32(reg);
599 limit = f1_read_config32(reg + 0x04);
600 /* Is this register allocated? */
601 if ((base & 3) != 0) {
602 unsigned nodeid, reg_link;
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300603 struct device *reg_dev;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200604 if (reg < 0xc0) { // mmio
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800605 nodeid = (limit & 0xf) + (base&0x30);
606 } else { // io
607 nodeid = (limit & 0xf) + ((base>>4)&0x30);
608 }
609 reg_link = (limit >> 4) & 7;
610 reg_dev = __f0_dev[nodeid];
611 if (reg_dev) {
612 /* Reserve the resource */
613 struct resource *res;
614 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
615 if (res) {
616 res->flags = 1;
617 }
618 }
619 }
620 }
621 /* FIXME: do we need to check extend conf space?
622 I don't believe that much preset value */
623
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800624 pci_domain_read_resources(dev);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800625}
626
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800627#if CONFIG_HW_MEM_HOLE_SIZEK != 0
628struct hw_mem_hole_info {
629 unsigned hole_startk;
630 int node_id;
631};
632static struct hw_mem_hole_info get_hw_mem_hole_info(void)
633{
634 struct hw_mem_hole_info mem_hole;
635 int i;
636 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
637 mem_hole.node_id = -1;
638 for (i = 0; i < node_nums; i++) {
639 dram_base_mask_t d;
640 u32 hole;
641 d = get_dram_base_mask(i);
642 if (!(d.mask & 1)) continue; // no memory on this node
643 hole = pci_read_config32(__f1_dev[i], 0xf0);
644 if (hole & 2) { // we find the hole
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200645 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800646 mem_hole.node_id = i; // record the node No with hole
647 break; // only one hole
648 }
649 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300650
651 /* We need to double check if there is special set on base reg and limit reg
652 * are not continuous instead of hole, it will find out its hole_startk.
653 */
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800654 if (mem_hole.node_id == -1) {
655 resource_t limitk_pri = 0;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200656 for (i = 0; i < node_nums; i++) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800657 dram_base_mask_t d;
658 resource_t base_k, limit_k;
659 d = get_dram_base_mask(i);
660 if (!(d.base & 1)) continue;
661 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
662 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
663 if (limitk_pri != base_k) { // we find the hole
664 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
665 mem_hole.node_id = i;
666 break; //only one hole
667 }
668 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
669 limitk_pri = limit_k;
670 }
671 }
672 return mem_hole;
673}
674#endif
675
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300676static void domain_set_resources(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800677{
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800678 unsigned long mmio_basek;
679 u32 pci_tolm;
680 int i, idx;
681 struct bus *link;
682#if CONFIG_HW_MEM_HOLE_SIZEK != 0
683 struct hw_mem_hole_info mem_hole;
684 u32 reset_memhole = 1;
685#endif
686
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800687 pci_tolm = 0xffffffffUL;
688 for (link = dev->link_list; link; link = link->next) {
689 pci_tolm = find_pci_tolm(link);
690 }
691
692 // FIXME handle interleaved nodes. If you fix this here, please fix
693 // amdk8, too.
694 mmio_basek = pci_tolm >> 10;
695 /* Round mmio_basek to something the processor can support */
696 mmio_basek &= ~((1 << 6) -1);
697
698 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
699 // MMIO hole. If you fix this here, please fix amdk8, too.
700 /* Round the mmio hole to 64M */
701 mmio_basek &= ~((64*1024) - 1);
702
703#if CONFIG_HW_MEM_HOLE_SIZEK != 0
704 /* if the hw mem hole is already set in raminit stage, here we will compare
705 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
706 * use hole_basek as mmio_basek and we don't need to reset hole.
707 * otherwise We reset the hole to the mmio_basek
708 */
709
710 mem_hole = get_hw_mem_hole_info();
711
712 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
713 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
714 mmio_basek = mem_hole.hole_startk;
715 reset_memhole = 0;
716 }
717#endif
718
719 idx = 0x10;
720 for (i = 0; i < node_nums; i++) {
721 dram_base_mask_t d;
722 resource_t basek, limitk, sizek; // 4 1T
723
724 d = get_dram_base_mask(i);
725
726 if (!(d.mask & 1)) continue;
727 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100728 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800729
730 sizek = limitk - basek;
731
732 /* see if we need a hole from 0xa0000 to 0xbffff */
733 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
734 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
735 idx += 0x10;
736 basek = (8*64)+(16*16);
737 sizek = limitk - ((8*64)+(16*16));
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800738 }
739
740 //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk);
741
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300742 /* split the region to accommodate pci memory space */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200743 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800744 if (basek <= mmio_basek) {
745 unsigned pre_sizek;
746 pre_sizek = mmio_basek - basek;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200747 if (pre_sizek > 0) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800748 ram_resource(dev, (idx | i), basek, pre_sizek);
749 idx += 0x10;
750 sizek -= pre_sizek;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800751 }
752 basek = mmio_basek;
753 }
754 if ((basek + sizek) <= 4*1024*1024) {
755 sizek = 0;
756 }
757 else {
758 uint64_t topmem2 = bsp_topmem2();
759 basek = 4*1024*1024;
760 sizek = topmem2/1024 - basek;
761 }
762 }
763
764 ram_resource(dev, (idx | i), basek, sizek);
765 idx += 0x10;
766 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
767 i, mmio_basek, basek, limitk);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800768 }
769
Kyösti Mälkki61be3602017-04-15 20:07:53 +0300770 add_uma_resource_below_tolm(dev, 7);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800771
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200772 for (link = dev->link_list; link; link = link->next) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800773 if (link->children) {
774 assign_resources(link);
775 }
776 }
777}
778
Kevin Cody-Little06d23232018-05-09 14:22:15 -0400779static const char *domain_acpi_name(const struct device *dev)
780{
781 if (dev->path.type == DEVICE_PATH_DOMAIN)
782 return "PCI0";
783
784 return NULL;
785}
786
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800787static struct device_operations pci_domain_ops = {
788 .read_resources = domain_read_resources,
789 .set_resources = domain_set_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100790 .init = DEVICE_NOOP,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800791 .scan_bus = pci_domain_scan_bus,
Kevin Cody-Little06d23232018-05-09 14:22:15 -0400792 .acpi_name = domain_acpi_name,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800793};
794
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300795static void sysconf_init(struct device *dev) // first node
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800796{
797 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
798 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
799}
800
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300801static void add_more_links(struct device *dev, unsigned total_links)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800802{
803 struct bus *link, *last = NULL;
804 int link_num;
805
806 for (link = dev->link_list; link; link = link->next)
807 last = link;
808
809 if (last) {
810 int links = total_links - last->link_num;
811 link_num = last->link_num;
812 if (links > 0) {
813 link = malloc(links*sizeof(*link));
814 if (!link)
815 die("Couldn't allocate more links!\n");
816 memset(link, 0, links*sizeof(*link));
817 last->next = link;
818 }
819 }
820 else {
821 link_num = -1;
822 link = malloc(total_links*sizeof(*link));
823 memset(link, 0, total_links*sizeof(*link));
824 dev->link_list = link;
825 }
826
827 for (link_num = link_num + 1; link_num < total_links; link_num++) {
828 link->link_num = link_num;
829 link->dev = dev;
830 link->next = link + 1;
831 last = link;
832 link = link->next;
833 }
834 last->next = NULL;
835}
836
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300837static void cpu_bus_scan(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800838{
839 struct bus *cpu_bus;
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300840 struct device *dev_mc;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800841 int i,j;
842 int coreid_bits;
843 int core_max = 0;
844 unsigned ApicIdCoreIdSize;
845 unsigned core_nums;
846 int siblings = 0;
847 unsigned int family;
848
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200849 dev_mc = pcidev_on_root(DEV_CDB, 0);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800850 if (!dev_mc) {
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200851 printk(BIOS_ERR, "0:%02x.0 not found", DEV_CDB);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800852 die("");
853 }
854 sysconf_init(dev_mc);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800855
856 /* Get Max Number of cores(MNC) */
Kyösti Mälkkid41feed2017-09-24 16:23:57 +0300857 coreid_bits = (cpuid_ecx(0x80000008) & 0x0000F000) >> 12;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800858 core_max = 1 << (coreid_bits & 0x000F); //mnc
859
860 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
861 if (ApicIdCoreIdSize) {
862 core_nums = (1 << ApicIdCoreIdSize) - 1;
863 } else {
864 core_nums = 3; //quad core
865 }
866
867 /* Find which cpus are present */
868 cpu_bus = dev->link_list;
869 for (i = 0; i < node_nums; i++) {
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300870 struct device *cdb_dev;
Kyösti Mälkkiedf51d22018-05-20 22:38:00 +0300871 unsigned devn;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800872 struct bus *pbus;
873
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200874 devn = DEV_CDB + i;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800875 pbus = dev_mc->bus;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800876
877 /* Find the cpu's pci device */
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300878 cdb_dev = pcidev_on_root(devn, 0);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800879 if (!cdb_dev) {
880 /* If I am probing things in a weird order
881 * ensure all of the cpu's pci devices are found.
882 */
883 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200884 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800885 cdb_dev = pci_probe_dev(NULL, pbus,
886 PCI_DEVFN(devn, fn));
887 }
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300888 cdb_dev = pcidev_on_root(devn, 0);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800889 } else {
890 /* Ok, We need to set the links for that device.
891 * otherwise the device under it will not be scanned
892 */
Kyösti Mälkki2a2d6132015-02-04 13:25:37 +0200893 add_more_links(cdb_dev, 4);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800894 }
895
896 family = cpuid_eax(1);
897 family = (family >> 20) & 0xFF;
898 if (family == 1) { //f10
899 u32 dword;
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300900 cdb_dev = pcidev_on_root(devn, 3);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800901 dword = pci_read_config32(cdb_dev, 0xe8);
902 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
903 } else if (family == 7) {//f16
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300904 cdb_dev = pcidev_on_root(devn, 5);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800905 if (cdb_dev && cdb_dev->enabled) {
906 siblings = pci_read_config32(cdb_dev, 0x84);
907 siblings &= 0xFF;
908 }
909 } else {
910 siblings = 0; //default one core
911 }
912 int enable_node = cdb_dev && cdb_dev->enabled;
913 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
914 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
915
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200916 for (j = 0; j <= siblings; j++) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800917 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
918 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
919 u32 lapicid_start = 0;
920
921 /*
922 * APIC ID calucation is tightly coupled with AGESA v5 code.
923 * This calculation MUST match the assignment calculation done
924 * in LocalApicInitializationAtEarly() function.
925 * And reference GetLocalApicIdForCore()
926 *
927 * Apply apic enumeration rules
928 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
929 * put the local-APICs at m..z
930 *
931 * This is needed because many IO-APIC devices only have 4 bits
932 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200933 */
Kyösti Mälkki50036322016-05-18 13:35:21 +0300934
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200935 u8 plat_num_io_apics = 3; /* FIXME */
Kyösti Mälkki50036322016-05-18 13:35:21 +0300936
937 if ((node_nums * core_max) + plat_num_io_apics >= 0x10) {
938 lapicid_start = (plat_num_io_apics - 1) / core_max;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800939 lapicid_start = (lapicid_start + 1) * core_max;
940 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
941 }
942 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
943 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
944 i, j, apic_id);
945
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300946 struct device *cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800947 if (cpu)
948 amd_cpu_topology(cpu, i, j);
949 } //j
950 }
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800951}
952
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300953static void cpu_bus_init(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800954{
955 initialize_cpus(dev->link_list);
956}
957
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800958static struct device_operations cpu_bus_ops = {
Edward O'Callaghan66c65322014-11-21 01:43:38 +1100959 .read_resources = DEVICE_NOOP,
960 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +1100961 .enable_resources = DEVICE_NOOP,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800962 .init = cpu_bus_init,
963 .scan_bus = cpu_bus_scan,
964};
965
966static void root_complex_enable_dev(struct device *dev)
967{
968 static int done = 0;
969
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800970 if (!done) {
971 setup_bsp_ramtop();
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800972 done = 1;
973 }
974
975 /* Set the operations if it is a special bus type */
976 if (dev->path.type == DEVICE_PATH_DOMAIN) {
977 dev->ops = &pci_domain_ops;
978 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
979 dev->ops = &cpu_bus_ops;
980 }
981}
982
983struct chip_operations northbridge_amd_agesa_family16kb_root_complex_ops = {
984 CHIP_NAME("AMD FAM16 Root Complex")
985 .enable_dev = root_complex_enable_dev,
986};
Bruce Griffith76db07e2013-07-07 02:06:53 -0600987
988/*********************************************************************
989 * Change the vendor / device IDs to match the generic VBIOS header. *
990 *********************************************************************/
991u32 map_oprom_vendev(u32 vendev)
992{
993 u32 new_vendev = vendev;
994
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +0100995 switch (vendev) {
Bruce Griffith76db07e2013-07-07 02:06:53 -0600996 case 0x10029830:
997 case 0x10029831:
998 case 0x10029832:
999 case 0x10029833:
1000 case 0x10029834:
1001 case 0x10029835:
1002 case 0x10029836:
1003 case 0x10029837:
1004 case 0x10029838:
1005 case 0x10029839:
1006 case 0x1002983A:
1007 case 0x1002983D:
1008 new_vendev = 0x10029830; // This is the default value in AMD-generated VBIOS
1009 break;
1010 default:
1011 break;
1012 }
1013
1014 if (vendev != new_vendev)
1015 printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev);
1016
1017 return new_vendev;
1018}