blob: d73ad72de03a9fd1bb4ac79d8c0117eb2b8a42f3 [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>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020018#include <device/pci_ops.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>
Martin Roth73e86a82013-01-17 16:28:30 -070030#include <AGESA.h>
zbao2c08f6a2012-07-02 15:32:58 +080031#include <cpu/x86/lapic.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +020032#include <cpu/amd/msr.h>
Kyösti Mälkkidbc47392012-08-05 12:11:40 +030033#include <cpu/amd/mtrr.h>
zbao2c08f6a2012-07-02 15:32:58 +080034#include <Porting.h>
zbao2c08f6a2012-07-02 15:32:58 +080035#include <Options.h>
36#include <Topology.h>
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +020037#include <northbridge/amd/agesa/nb_common.h>
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020038#include <northbridge/amd/agesa/state_machine.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020039#include <northbridge/amd/agesa/agesa_helper.h>
zbao2c08f6a2012-07-02 15:32:58 +080040
Kyösti Mälkki113f6702018-05-20 20:12:32 +030041#define MAX_NODE_NUMS MAX_NODES
zbao2c08f6a2012-07-02 15:32:58 +080042
zbao2c08f6a2012-07-02 15:32:58 +080043typedef struct dram_base_mask {
44 u32 base; //[47:27] at [28:8]
45 u32 mask; //[47:27] at [28:8] and enable at bit 0
46} dram_base_mask_t;
47
Subrata Banikb1434fc2019-03-15 22:20:41 +053048static unsigned int node_nums;
49static unsigned int sblink;
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030050static struct device *__f0_dev[MAX_NODE_NUMS];
51static struct device *__f1_dev[MAX_NODE_NUMS];
52static struct device *__f2_dev[MAX_NODE_NUMS];
53static struct device *__f4_dev[MAX_NODE_NUMS];
Subrata Banikb1434fc2019-03-15 22:20:41 +053054static unsigned int fx_devs = 0;
zbao2c08f6a2012-07-02 15:32:58 +080055
56static dram_base_mask_t get_dram_base_mask(u32 nodeid)
57{
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030058 struct device *dev;
zbao2c08f6a2012-07-02 15:32:58 +080059 dram_base_mask_t d;
60 dev = __f1_dev[0];
61 u32 temp;
62 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
63 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
64 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020065 d.mask |= temp << 21;
zbao2c08f6a2012-07-02 15:32:58 +080066 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
67 d.mask |= (temp & 1); // enable bit
68 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
69 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020070 d.base |= temp << 21;
zbao2c08f6a2012-07-02 15:32:58 +080071 return d;
72}
73
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030074static void set_io_addr_reg(struct device *dev, u32 nodeid, u32 linkn, u32 reg,
zbao2c08f6a2012-07-02 15:32:58 +080075 u32 io_min, u32 io_max)
76{
77 u32 i;
78 u32 tempreg;
79 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020080 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn << 4) | ((io_max&0xf0)<<(12-4)); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020081 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +080082 pci_write_config32(__f1_dev[i], reg+4, tempreg);
Elyes HAOUAS27e18012017-06-27 23:14:51 +020083 tempreg = 3 /*| (3 << 4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
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, tempreg);
86}
87
88static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
89{
90 u32 i;
91 u32 tempreg;
92 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020093 tempreg = (nodeid&0xf) | (linkn << 4) | (mmio_max&0xffffff00); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020094 for (i = 0; i < nodes; i++)
zbao2c08f6a2012-07-02 15:32:58 +080095 pci_write_config32(__f1_dev[i], reg+4, tempreg);
96 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020097 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +080098 pci_write_config32(__f1_dev[i], reg, tempreg);
99}
100
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300101static struct device *get_node_pci(u32 nodeid, u32 fn)
zbao2c08f6a2012-07-02 15:32:58 +0800102{
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200103 return pcidev_on_root(DEV_CDB + nodeid, fn);
zbao2c08f6a2012-07-02 15:32:58 +0800104}
105
106static void get_fx_devs(void)
107{
108 int i;
109 for (i = 0; i < MAX_NODE_NUMS; i++) {
110 __f0_dev[i] = get_node_pci(i, 0);
111 __f1_dev[i] = get_node_pci(i, 1);
112 __f2_dev[i] = get_node_pci(i, 2);
113 __f4_dev[i] = get_node_pci(i, 4);
114 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
115 fx_devs = i+1;
116 }
117 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
118 die("Cannot find 0:0x18.[0|1]\n");
119 }
120 printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs);
121}
122
Subrata Banikb1434fc2019-03-15 22:20:41 +0530123static u32 f1_read_config32(unsigned int reg)
zbao2c08f6a2012-07-02 15:32:58 +0800124{
125 if (fx_devs == 0)
126 get_fx_devs();
127 return pci_read_config32(__f1_dev[0], reg);
128}
129
Subrata Banikb1434fc2019-03-15 22:20:41 +0530130static void f1_write_config32(unsigned int reg, u32 value)
zbao2c08f6a2012-07-02 15:32:58 +0800131{
132 int i;
133 if (fx_devs == 0)
134 get_fx_devs();
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200135 for (i = 0; i < fx_devs; i++) {
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300136 struct device *dev;
zbao2c08f6a2012-07-02 15:32:58 +0800137 dev = __f1_dev[i];
138 if (dev && dev->enabled) {
139 pci_write_config32(dev, reg, value);
140 }
141 }
142}
143
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300144static u32 amdfam15_nodeid(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800145{
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200146 return (dev->path.pci.devfn >> 3) - DEV_CDB;
zbao2c08f6a2012-07-02 15:32:58 +0800147}
148
149static void set_vga_enable_reg(u32 nodeid, u32 linkn)
150{
151 u32 val;
152
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200153 val = 1 | (nodeid << 4) | (linkn << 12);
zbao2c08f6a2012-07-02 15:32:58 +0800154 /* it will routing
155 * (1)mmio 0xa0000:0xbffff
156 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
157 */
158 f1_write_config32(0xf4, val);
159
160}
161
162/**
163 * @return
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100164 * @retval 2 resoure does not exist, usable
165 * @retval 0 resource exists, not usable
zbao2c08f6a2012-07-02 15:32:58 +0800166 * @retval 1 resource exist, resource has been allocated before
167 */
Subrata Banikb1434fc2019-03-15 22:20:41 +0530168static int reg_useable(unsigned int reg, struct device *goal_dev,
169 unsigned int goal_nodeid, unsigned int goal_link)
zbao2c08f6a2012-07-02 15:32:58 +0800170{
171 struct resource *res;
Subrata Banikb1434fc2019-03-15 22:20:41 +0530172 unsigned int nodeid, link = 0;
zbao2c08f6a2012-07-02 15:32:58 +0800173 int result;
174 res = 0;
175 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300176 struct device *dev;
zbao2c08f6a2012-07-02 15:32:58 +0800177 dev = __f0_dev[nodeid];
178 if (!dev)
179 continue;
180 for (link = 0; !res && (link < 8); link++) {
181 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
182 }
183 }
184 result = 2;
185 if (res) {
186 result = 0;
187 if ((goal_link == (link - 1)) &&
188 (goal_nodeid == (nodeid - 1)) &&
189 (res->flags <= 1)) {
190 result = 1;
191 }
192 }
193 return result;
194}
195
Subrata Banikb1434fc2019-03-15 22:20:41 +0530196static struct resource *amdfam15_find_iopair(struct device *dev,
197 unsigned int nodeid, unsigned int link)
zbao2c08f6a2012-07-02 15:32:58 +0800198{
199 struct resource *resource;
200 u32 free_reg, reg;
201 resource = 0;
202 free_reg = 0;
203 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
204 int result;
205 result = reg_useable(reg, dev, nodeid, link);
206 if (result == 1) {
207 /* I have been allocated this one */
208 break;
209 }
210 else if (result > 1) {
211 /* I have a free register pair */
212 free_reg = reg;
213 }
214 }
215 if (reg > 0xd8) {
216 reg = free_reg; // if no free, the free_reg still be 0
217 }
218
219 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
220
221 return resource;
222}
223
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300224static struct resource *amdfam15_find_mempair(struct device *dev, u32 nodeid, u32 link)
zbao2c08f6a2012-07-02 15:32:58 +0800225{
226 struct resource *resource;
227 u32 free_reg, reg;
228 resource = 0;
229 free_reg = 0;
230 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
231 int result;
232 result = reg_useable(reg, dev, nodeid, link);
233 if (result == 1) {
234 /* I have been allocated this one */
235 break;
236 }
237 else if (result > 1) {
238 /* I have a free register pair */
239 free_reg = reg;
240 }
241 }
242 if (reg > 0xb8) {
243 reg = free_reg;
244 }
245
246 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
247 return resource;
248}
249
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300250static void amdfam15_link_read_bases(struct device *dev, u32 nodeid, u32 link)
zbao2c08f6a2012-07-02 15:32:58 +0800251{
252 struct resource *resource;
253
254 /* Initialize the io space constraints on the current bus */
255 resource = amdfam15_find_iopair(dev, nodeid, link);
256 if (resource) {
257 u32 align;
258 align = log2(HT_IO_HOST_ALIGN);
259 resource->base = 0;
260 resource->size = 0;
261 resource->align = align;
262 resource->gran = align;
263 resource->limit = 0xffffUL;
264 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
265 }
266
267 /* Initialize the prefetchable memory constraints on the current bus */
268 resource = amdfam15_find_mempair(dev, nodeid, link);
269 if (resource) {
270 resource->base = 0;
271 resource->size = 0;
272 resource->align = log2(HT_MEM_HOST_ALIGN);
273 resource->gran = log2(HT_MEM_HOST_ALIGN);
274 resource->limit = 0xffffffffffULL;
275 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
276 resource->flags |= IORESOURCE_BRIDGE;
277 }
278
279 /* Initialize the memory constraints on the current bus */
280 resource = amdfam15_find_mempair(dev, nodeid, link);
281 if (resource) {
282 resource->base = 0;
283 resource->size = 0;
284 resource->align = log2(HT_MEM_HOST_ALIGN);
285 resource->gran = log2(HT_MEM_HOST_ALIGN);
286 resource->limit = 0xffffffffffULL;
287 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
288 }
289
290}
291
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300292static void nb_read_resources(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800293{
294 u32 nodeid;
295 struct bus *link;
296
297 nodeid = amdfam15_nodeid(dev);
298 for (link = dev->link_list; link; link = link->next) {
299 if (link->children) {
300 amdfam15_link_read_bases(dev, nodeid, link->link_num);
301 }
302 }
Steven Sherk1cbabb02013-02-01 09:22:35 -0700303
304 /*
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800305 * This MMCONF resource must be reserved in the PCI domain.
Steven Sherk1cbabb02013-02-01 09:22:35 -0700306 * It is not honored by the coreboot resource allocator if it is in
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800307 * the CPU_CLUSTER.
Steven Sherk1cbabb02013-02-01 09:22:35 -0700308 */
Elyes HAOUAS400ce552018-10-12 10:54:30 +0200309 mmconf_resource(dev, MMIO_CONF_BASE);
zbao2c08f6a2012-07-02 15:32:58 +0800310}
311
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300312static void set_resource(struct device *dev, struct resource *resource, u32 nodeid)
zbao2c08f6a2012-07-02 15:32:58 +0800313{
314 resource_t rbase, rend;
Subrata Banikb1434fc2019-03-15 22:20:41 +0530315 unsigned int reg, link_num;
zbao2c08f6a2012-07-02 15:32:58 +0800316 char buf[50];
317
318 /* Make certain the resource has actually been set */
319 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
320 return;
321 }
322
323 /* If I have already stored this resource don't worry about it */
324 if (resource->flags & IORESOURCE_STORED) {
325 return;
326 }
327
328 /* Only handle PCI memory and IO resources */
329 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
330 return;
331
332 /* Ensure I am actually looking at a resource of function 1 */
333 if ((resource->index & 0xffff) < 0x1000) {
334 return;
335 }
336 /* Get the base address */
337 rbase = resource->base;
338
339 /* Get the limit (rounded up) */
340 rend = resource_end(resource);
341
342 /* Get the register and link */
343 reg = resource->index & 0xfff; // 4k
344 link_num = IOINDEX_LINK(resource->index);
345
346 if (resource->flags & IORESOURCE_IO) {
347 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
348 }
349 else if (resource->flags & IORESOURCE_MEM) {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100350 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 +0800351 }
352 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200353 snprintf(buf, sizeof(buf), " <node %x link %x>",
zbao2c08f6a2012-07-02 15:32:58 +0800354 nodeid, link_num);
355 report_resource_stored(dev, resource, buf);
356}
357
358/**
359 * I tried to reuse the resource allocation code in set_resource()
360 * but it is too difficult to deal with the resource allocation magic.
361 */
362
Subrata Banikb1434fc2019-03-15 22:20:41 +0530363static void create_vga_resource(struct device *dev, unsigned int nodeid)
zbao2c08f6a2012-07-02 15:32:58 +0800364{
365 struct bus *link;
366
367 /* find out which link the VGA card is connected,
368 * we only deal with the 'first' vga card */
369 for (link = dev->link_list; link; link = link->next) {
370 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800371#if CONFIG(MULTIPLE_VGA_ADAPTERS)
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300372 extern struct device *vga_pri; // the primary vga device, defined in device.c
zbao2c08f6a2012-07-02 15:32:58 +0800373 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
374 link->secondary,link->subordinate);
375 /* We need to make sure the vga_pri is under the link */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200376 if ((vga_pri->bus->secondary >= link->secondary) &&
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300377 (vga_pri->bus->secondary <= link->subordinate))
zbao2c08f6a2012-07-02 15:32:58 +0800378#endif
379 break;
380 }
381 }
382
383 /* no VGA card installed */
384 if (link == NULL)
385 return;
386
387 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
388 set_vga_enable_reg(nodeid, sblink);
389}
390
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300391static void nb_set_resources(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800392{
Subrata Banikb1434fc2019-03-15 22:20:41 +0530393 unsigned int nodeid;
zbao2c08f6a2012-07-02 15:32:58 +0800394 struct bus *bus;
395 struct resource *res;
396
397 /* Find the nodeid */
398 nodeid = amdfam15_nodeid(dev);
399
400 create_vga_resource(dev, nodeid); //TODO: do we need this?
401
402 /* Set each resource we have found */
403 for (res = dev->resource_list; res; res = res->next) {
404 set_resource(dev, res, nodeid);
405 }
406
407 for (bus = dev->link_list; bus; bus = bus->next) {
408 if (bus->children) {
409 assign_resources(bus);
410 }
411 }
412}
413
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100414static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200415{
416 void *addr, *current;
417
418 /* Skip the HEST header. */
419 current = (void *)(hest + 1);
420
421 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
422 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700423 current += acpi_create_hest_error_source(hest, current, 0,
424 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200425
426 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
427 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700428 current += acpi_create_hest_error_source(hest, current, 1,
429 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200430
431 return (unsigned long)current;
432}
433
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300434static void northbridge_fill_ssdt_generator(struct device *device)
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200435{
436 msr_t msr;
437 char pscope[] = "\\_SB.PCI0";
438
439 acpigen_write_scope(pscope);
440 msr = rdmsr(TOP_MEM);
441 acpigen_write_name_dword("TOM1", msr.lo);
442 msr = rdmsr(TOP_MEM2);
443 /*
444 * Since XP only implements parts of ACPI 2.0, we can't use a qword
445 * here.
446 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
447 * slide 22ff.
448 * Shift value right by 20 bit to make it fit into 32bit,
449 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
450 */
451 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
452 acpigen_pop_len();
453}
454
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300455static unsigned long agesa_write_acpi_tables(struct device *device,
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200456 unsigned long current,
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200457 acpi_rsdp_t *rsdp)
458{
459 acpi_srat_t *srat;
460 acpi_slit_t *slit;
461 acpi_header_t *ssdt;
462 acpi_header_t *alib;
463 acpi_header_t *ivrs;
464 acpi_hest_t *hest;
465
466 /* HEST */
467 current = ALIGN(current, 8);
468 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100469 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200470 acpi_add_table(rsdp, (void *)current);
471 current += ((acpi_header_t *)current)->length;
472
473 current = ALIGN(current, 8);
474 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
475 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
476 if (ivrs != NULL) {
477 memcpy((void *)current, ivrs, ivrs->length);
478 ivrs = (acpi_header_t *) current;
479 current += ivrs->length;
480 acpi_add_table(rsdp, ivrs);
481 } else {
482 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
483 }
484
485 /* SRAT */
486 current = ALIGN(current, 8);
487 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
488 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
489 if (srat != NULL) {
490 memcpy((void *)current, srat, srat->header.length);
491 srat = (acpi_srat_t *) current;
492 current += srat->header.length;
493 acpi_add_table(rsdp, srat);
494 } else {
495 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
496 }
497
498 /* SLIT */
499 current = ALIGN(current, 8);
500 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
501 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
502 if (slit != NULL) {
503 memcpy((void *)current, slit, slit->header.length);
504 slit = (acpi_slit_t *) current;
505 current += slit->header.length;
506 acpi_add_table(rsdp, slit);
507 } else {
508 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
509 }
510
511 /* ALIB */
512 current = ALIGN(current, 16);
513 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
514 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
515 if (alib != NULL) {
516 memcpy((void *)current, alib, alib->length);
517 alib = (acpi_header_t *) current;
518 current += alib->length;
519 acpi_add_table(rsdp, (void *)alib);
520 }
521 else {
522 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
523 }
524
525 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
526 /* SSDT */
527 current = ALIGN(current, 16);
528 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
529 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
530 if (ssdt != NULL) {
531 memcpy((void *)current, ssdt, ssdt->length);
532 ssdt = (acpi_header_t *) current;
533 current += ssdt->length;
534 }
535 else {
536 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
537 }
538 acpi_add_table(rsdp,ssdt);
539
540 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
541
542 return current;
543}
544
545
zbao2c08f6a2012-07-02 15:32:58 +0800546static struct device_operations northbridge_operations = {
Steven Sherkf4340582013-01-29 16:13:35 -0700547 .read_resources = nb_read_resources,
548 .set_resources = nb_set_resources,
zbao2c08f6a2012-07-02 15:32:58 +0800549 .enable_resources = pci_dev_enable_resources,
Edward O'Callaghand994ef12014-11-21 02:22:33 +1100550 .init = DEVICE_NOOP,
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200551 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
552 .write_acpi_tables = agesa_write_acpi_tables,
zbao2c08f6a2012-07-02 15:32:58 +0800553 .enable = 0,
554 .ops_pci = 0,
555};
556
557static const struct pci_driver family15_northbridge __pci_driver = {
558 .ops = &northbridge_operations,
559 .vendor = PCI_VENDOR_ID_AMD,
Marshall Dawson463f46e2016-10-14 20:46:08 -0600560 .device = PCI_DEVICE_ID_AMD_15H_MODEL_101F_NB_HT,
zbao2c08f6a2012-07-02 15:32:58 +0800561};
562
563static const struct pci_driver family10_northbridge __pci_driver = {
564 .ops = &northbridge_operations,
565 .vendor = PCI_VENDOR_ID_AMD,
566 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
567};
568
569struct chip_operations northbridge_amd_agesa_family15tn_ops = {
570 CHIP_NAME("AMD FAM15 Northbridge")
571 .enable_dev = 0,
572};
573
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300574static void domain_read_resources(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800575{
Subrata Banikb1434fc2019-03-15 22:20:41 +0530576 unsigned int reg;
zbao2c08f6a2012-07-02 15:32:58 +0800577
578 /* Find the already assigned resource pairs */
579 get_fx_devs();
580 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
581 u32 base, limit;
582 base = f1_read_config32(reg);
583 limit = f1_read_config32(reg + 0x04);
584 /* Is this register allocated? */
585 if ((base & 3) != 0) {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530586 unsigned int nodeid, reg_link;
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300587 struct device *reg_dev;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200588 if (reg < 0xc0) { // mmio
zbao2c08f6a2012-07-02 15:32:58 +0800589 nodeid = (limit & 0xf) + (base&0x30);
590 } else { // io
591 nodeid = (limit & 0xf) + ((base>>4)&0x30);
592 }
593 reg_link = (limit >> 4) & 7;
594 reg_dev = __f0_dev[nodeid];
595 if (reg_dev) {
596 /* Reserve the resource */
597 struct resource *res;
598 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
599 if (res) {
600 res->flags = 1;
601 }
602 }
603 }
604 }
605 /* FIXME: do we need to check extend conf space?
606 I don't believe that much preset value */
607
zbao2c08f6a2012-07-02 15:32:58 +0800608 pci_domain_read_resources(dev);
zbao2c08f6a2012-07-02 15:32:58 +0800609}
610
zbao2c08f6a2012-07-02 15:32:58 +0800611#if CONFIG_HW_MEM_HOLE_SIZEK != 0
612struct hw_mem_hole_info {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530613 unsigned int hole_startk;
zbao2c08f6a2012-07-02 15:32:58 +0800614 int node_id;
615};
616static struct hw_mem_hole_info get_hw_mem_hole_info(void)
617{
618 struct hw_mem_hole_info mem_hole;
619 int i;
620 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
621 mem_hole.node_id = -1;
622 for (i = 0; i < node_nums; i++) {
623 dram_base_mask_t d;
624 u32 hole;
625 d = get_dram_base_mask(i);
626 if (!(d.mask & 1)) continue; // no memory on this node
627 hole = pci_read_config32(__f1_dev[i], 0xf0);
628 if (hole & 1) { // we find the hole
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200629 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
zbao2c08f6a2012-07-02 15:32:58 +0800630 mem_hole.node_id = i; // record the node No with hole
631 break; // only one hole
632 }
633 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300634
635 /* We need to double check if there is special set on base reg and limit reg
636 * are not continuous instead of hole, it will find out its hole_startk.
637 */
zbao2c08f6a2012-07-02 15:32:58 +0800638 if (mem_hole.node_id == -1) {
639 resource_t limitk_pri = 0;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200640 for (i = 0; i < node_nums; i++) {
zbao2c08f6a2012-07-02 15:32:58 +0800641 dram_base_mask_t d;
642 resource_t base_k, limit_k;
643 d = get_dram_base_mask(i);
644 if (!(d.base & 1)) continue;
645 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
646 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
647 if (limitk_pri != base_k) { // we find the hole
648 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
649 mem_hole.node_id = i;
650 break; //only one hole
651 }
zbao15dc3cc2012-08-03 15:56:21 +0800652 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800653 limitk_pri = limit_k;
654 }
655 }
656 return mem_hole;
657}
658#endif
659
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300660static void domain_set_resources(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800661{
zbao2c08f6a2012-07-02 15:32:58 +0800662 unsigned long mmio_basek;
663 u32 pci_tolm;
664 int i, idx;
665 struct bus *link;
666#if CONFIG_HW_MEM_HOLE_SIZEK != 0
667 struct hw_mem_hole_info mem_hole;
668 u32 reset_memhole = 1;
669#endif
670
zbao2c08f6a2012-07-02 15:32:58 +0800671 pci_tolm = 0xffffffffUL;
672 for (link = dev->link_list; link; link = link->next) {
673 pci_tolm = find_pci_tolm(link);
674 }
675
676 // FIXME handle interleaved nodes. If you fix this here, please fix
677 // amdk8, too.
678 mmio_basek = pci_tolm >> 10;
679 /* Round mmio_basek to something the processor can support */
680 mmio_basek &= ~((1 << 6) -1);
681
682 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
683 // MMIO hole. If you fix this here, please fix amdk8, too.
684 /* Round the mmio hole to 64M */
685 mmio_basek &= ~((64*1024) - 1);
686
687#if CONFIG_HW_MEM_HOLE_SIZEK != 0
688 /* if the hw mem hole is already set in raminit stage, here we will compare
689 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
690 * use hole_basek as mmio_basek and we don't need to reset hole.
691 * otherwise We reset the hole to the mmio_basek
692 */
693
694 mem_hole = get_hw_mem_hole_info();
695
696 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
697 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
698 mmio_basek = mem_hole.hole_startk;
699 reset_memhole = 0;
700 }
701#endif
702
703 idx = 0x10;
704 for (i = 0; i < node_nums; i++) {
705 dram_base_mask_t d;
706 resource_t basek, limitk, sizek; // 4 1T
707
708 d = get_dram_base_mask(i);
709
710 if (!(d.mask & 1)) continue;
711 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100712 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800713
714 sizek = limitk - basek;
715
716 /* see if we need a hole from 0xa0000 to 0xbffff */
717 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
718 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
719 idx += 0x10;
720 basek = (8*64)+(16*16);
721 sizek = limitk - ((8*64)+(16*16));
722
723 }
724
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300725 /* split the region to accommodate pci memory space */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200726 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
zbao2c08f6a2012-07-02 15:32:58 +0800727 if (basek <= mmio_basek) {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530728 unsigned int pre_sizek;
zbao2c08f6a2012-07-02 15:32:58 +0800729 pre_sizek = mmio_basek - basek;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200730 if (pre_sizek > 0) {
zbao2c08f6a2012-07-02 15:32:58 +0800731 ram_resource(dev, (idx | i), basek, pre_sizek);
732 idx += 0x10;
733 sizek -= pre_sizek;
zbao2c08f6a2012-07-02 15:32:58 +0800734 }
735 basek = mmio_basek;
736 }
737 if ((basek + sizek) <= 4*1024*1024) {
738 sizek = 0;
739 }
740 else {
Siyuan Wang29840e22013-06-04 19:56:22 +0800741 uint64_t topmem2 = bsp_topmem2();
zbao2c08f6a2012-07-02 15:32:58 +0800742 basek = 4*1024*1024;
Siyuan Wang29840e22013-06-04 19:56:22 +0800743 sizek = topmem2/1024 - basek;
zbao2c08f6a2012-07-02 15:32:58 +0800744 }
745 }
746
zbao2c08f6a2012-07-02 15:32:58 +0800747 ram_resource(dev, (idx | i), basek, sizek);
748 idx += 0x10;
zbao2c08f6a2012-07-02 15:32:58 +0800749 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
750 i, mmio_basek, basek, limitk);
zbao2c08f6a2012-07-02 15:32:58 +0800751 }
752
Kyösti Mälkki61be3602017-04-15 20:07:53 +0300753 add_uma_resource_below_tolm(dev, 7);
zbao2c08f6a2012-07-02 15:32:58 +0800754
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200755 for (link = dev->link_list; link; link = link->next) {
zbao2c08f6a2012-07-02 15:32:58 +0800756 if (link->children) {
757 assign_resources(link);
758 }
759 }
760}
761
762static struct device_operations pci_domain_ops = {
763 .read_resources = domain_read_resources,
764 .set_resources = domain_set_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100765 .init = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +0800766 .scan_bus = pci_domain_scan_bus,
zbao2c08f6a2012-07-02 15:32:58 +0800767};
768
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300769static void sysconf_init(struct device *dev) // first node
zbao2c08f6a2012-07-02 15:32:58 +0800770{
771 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
772 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
773}
774
Subrata Banikb1434fc2019-03-15 22:20:41 +0530775static void add_more_links(struct device *dev, unsigned int total_links)
zbao2c08f6a2012-07-02 15:32:58 +0800776{
777 struct bus *link, *last = NULL;
778 int link_num;
779
780 for (link = dev->link_list; link; link = link->next)
781 last = link;
782
783 if (last) {
784 int links = total_links - last->link_num;
785 link_num = last->link_num;
786 if (links > 0) {
787 link = malloc(links*sizeof(*link));
788 if (!link)
789 die("Couldn't allocate more links!\n");
790 memset(link, 0, links*sizeof(*link));
791 last->next = link;
792 }
793 }
794 else {
795 link_num = -1;
796 link = malloc(total_links*sizeof(*link));
797 memset(link, 0, total_links*sizeof(*link));
798 dev->link_list = link;
799 }
800
801 for (link_num = link_num + 1; link_num < total_links; link_num++) {
802 link->link_num = link_num;
803 link->dev = dev;
804 link->next = link + 1;
805 last = link;
806 link = link->next;
807 }
808 last->next = NULL;
809}
810
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300811static void cpu_bus_scan(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800812{
813 struct bus *cpu_bus;
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300814 struct device *dev_mc;
zbao2c08f6a2012-07-02 15:32:58 +0800815 int i,j;
816 int coreid_bits;
817 int core_max = 0;
Subrata Banikb1434fc2019-03-15 22:20:41 +0530818 unsigned int ApicIdCoreIdSize;
819 unsigned int core_nums;
zbao2c08f6a2012-07-02 15:32:58 +0800820 int siblings = 0;
821 unsigned int family;
822
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200823 dev_mc = pcidev_on_root(DEV_CDB, 0);
zbao2c08f6a2012-07-02 15:32:58 +0800824 if (!dev_mc) {
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200825 printk(BIOS_ERR, "0:%02x.0 not found", DEV_CDB);
zbao2c08f6a2012-07-02 15:32:58 +0800826 die("");
827 }
828 sysconf_init(dev_mc);
zbao2c08f6a2012-07-02 15:32:58 +0800829
830 /* Get Max Number of cores(MNC) */
Kyösti Mälkkid41feed2017-09-24 16:23:57 +0300831 coreid_bits = (cpuid_ecx(0x80000008) & 0x0000F000) >> 12;
zbao2c08f6a2012-07-02 15:32:58 +0800832 core_max = 1 << (coreid_bits & 0x000F); //mnc
833
834 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
835 if (ApicIdCoreIdSize) {
836 core_nums = (1 << ApicIdCoreIdSize) - 1;
837 } else {
838 core_nums = 3; //quad core
839 }
840
841 /* Find which cpus are present */
842 cpu_bus = dev->link_list;
843 for (i = 0; i < node_nums; i++) {
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300844 struct device *cdb_dev;
Subrata Banikb1434fc2019-03-15 22:20:41 +0530845 unsigned int devn;
zbao2c08f6a2012-07-02 15:32:58 +0800846 struct bus *pbus;
847
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200848 devn = DEV_CDB + i;
zbao2c08f6a2012-07-02 15:32:58 +0800849 pbus = dev_mc->bus;
zbao2c08f6a2012-07-02 15:32:58 +0800850
851 /* Find the cpu's pci device */
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300852 cdb_dev = pcidev_on_root(devn, 0);
zbao2c08f6a2012-07-02 15:32:58 +0800853 if (!cdb_dev) {
854 /* If I am probing things in a weird order
855 * ensure all of the cpu's pci devices are found.
856 */
857 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200858 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
zbao2c08f6a2012-07-02 15:32:58 +0800859 cdb_dev = pci_probe_dev(NULL, pbus,
860 PCI_DEVFN(devn, fn));
861 }
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300862 cdb_dev = pcidev_on_root(devn, 0);
zbao2c08f6a2012-07-02 15:32:58 +0800863 } else {
864 /* Ok, We need to set the links for that device.
865 * otherwise the device under it will not be scanned
866 */
Kyösti Mälkki2a2d6132015-02-04 13:25:37 +0200867 add_more_links(cdb_dev, 4);
zbao2c08f6a2012-07-02 15:32:58 +0800868 }
869
870 family = cpuid_eax(1);
871 family = (family >> 20) & 0xFF;
872 if (family == 1) { //f10
873 u32 dword;
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300874 cdb_dev = pcidev_on_root(devn, 3);
zbao2c08f6a2012-07-02 15:32:58 +0800875 dword = pci_read_config32(cdb_dev, 0xe8);
876 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
877 } else if (family == 6) {//f15
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300878 cdb_dev = pcidev_on_root(devn, 5);
zbao2c08f6a2012-07-02 15:32:58 +0800879 if (cdb_dev && cdb_dev->enabled) {
880 siblings = pci_read_config32(cdb_dev, 0x84);
881 siblings &= 0xFF;
882 }
883 } else {
884 siblings = 0; //default one core
885 }
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300886 int enable_node = cdb_dev && cdb_dev->enabled;
zbao2c08f6a2012-07-02 15:32:58 +0800887 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
888 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
889
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200890 for (j = 0; j <= siblings; j++) {
zbao2c08f6a2012-07-02 15:32:58 +0800891 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
892 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
893 u32 lapicid_start = 0;
894
zbao2c08f6a2012-07-02 15:32:58 +0800895 /*
896 * APIC ID calucation is tightly coupled with AGESA v5 code.
897 * This calculation MUST match the assignment calculation done
898 * in LocalApicInitializationAtEarly() function.
899 * And reference GetLocalApicIdForCore()
900 *
901 * Apply apic enumeration rules
902 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
903 * put the local-APICs at m..z
904 *
905 * This is needed because many IO-APIC devices only have 4 bits
906 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200907 */
Kyösti Mälkki50036322016-05-18 13:35:21 +0300908
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200909 u8 plat_num_io_apics = 3; /* FIXME */
Kyösti Mälkki50036322016-05-18 13:35:21 +0300910
911 if ((node_nums * core_max) + plat_num_io_apics >= 0x10) {
912 lapicid_start = (plat_num_io_apics - 1) / core_max;
zbao2c08f6a2012-07-02 15:32:58 +0800913 lapicid_start = (lapicid_start + 1) * core_max;
914 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
915 }
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300916 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
zbao2c08f6a2012-07-02 15:32:58 +0800917 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300918 i, j, apic_id);
zbao2c08f6a2012-07-02 15:32:58 +0800919
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300920 struct device *cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300921 if (cpu)
922 amd_cpu_topology(cpu, i, j);
zbao2c08f6a2012-07-02 15:32:58 +0800923 } //j
924 }
zbao2c08f6a2012-07-02 15:32:58 +0800925}
926
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300927static void cpu_bus_init(struct device *dev)
zbao2c08f6a2012-07-02 15:32:58 +0800928{
929 initialize_cpus(dev->link_list);
930}
931
zbao2c08f6a2012-07-02 15:32:58 +0800932static struct device_operations cpu_bus_ops = {
Edward O'Callaghan2837ab22014-11-06 08:57:40 +1100933 .read_resources = DEVICE_NOOP,
934 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +1100935 .enable_resources = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +0800936 .init = cpu_bus_init,
937 .scan_bus = cpu_bus_scan,
938};
939
940static void root_complex_enable_dev(struct device *dev)
941{
Kyösti Mälkki87213b62012-08-27 20:00:33 +0300942 static int done = 0;
943
Kyösti Mälkki87213b62012-08-27 20:00:33 +0300944 if (!done) {
945 setup_bsp_ramtop();
Kyösti Mälkki87213b62012-08-27 20:00:33 +0300946 done = 1;
947 }
948
zbao2c08f6a2012-07-02 15:32:58 +0800949 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800950 if (dev->path.type == DEVICE_PATH_DOMAIN) {
zbao2c08f6a2012-07-02 15:32:58 +0800951 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800952 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
zbao2c08f6a2012-07-02 15:32:58 +0800953 dev->ops = &cpu_bus_ops;
954 }
955}
956
957struct chip_operations northbridge_amd_agesa_family15tn_root_complex_ops = {
Kyösti Mälkki2900d4b2017-07-25 14:55:29 +0300958 CHIP_NAME("AMD Family 15tn Root Complex")
zbao2c08f6a2012-07-02 15:32:58 +0800959 .enable_dev = root_complex_enable_dev,
960};
Dave Frodincbf3d402012-12-05 08:20:12 -0700961
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100962/*********************************************************************
963 * Change the vendor / device IDs to match the generic VBIOS header. *
964 *********************************************************************/
Dave Frodincbf3d402012-12-05 08:20:12 -0700965u32 map_oprom_vendev(u32 vendev)
966{
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100967 u32 new_vendev = vendev;
Dave Frodincbf3d402012-12-05 08:20:12 -0700968
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +0100969 switch (vendev) {
Bruce Griffith42e11f52013-07-08 18:19:08 -0600970 case 0x10029900: /* AMD Radeon HD 7660G (Trinity) */
971 case 0x10029901: /* AMD Radeon HD 7660D (Trinity) */
972 case 0x10029903: /* AMD Radeon HD 7640G (Trinity) */
973 case 0x10029904: /* AMD Radeon HD 7560D (Trinity) */
974 case 0x10029907: /* AMD Radeon HD 7620G (Trinity) */
975 case 0x10029908: /* AMD Radeon HD 7600G (Trinity) */
976 case 0x1002990A: /* AMD Radeon HD 7500G (Trinity) */
977 case 0x1002990B: /* AMD Radeon HD 8650G (Richland) */
978 case 0x1002990C: /* AMD Radeon HD 8670D (Richland) */
979 case 0x1002990D: /* AMD Radeon HD 8550G (Richland) */
980 case 0x1002990E: /* AMD Radeon HD 8570D (Richland) */
981 case 0x1002990F: /* AMD Radeon HD 8610G (Richland) */
982 case 0x10029910: /* AMD Radeon HD 7660G (Trinity) */
983 case 0x10029913: /* AMD Radeon HD 7640G (Trinity) */
984 case 0x10029917: /* AMD Radeon HD 7620G (Trinity) */
985 case 0x10029918: /* AMD Radeon HD 7600G (Trinity) */
986 case 0x10029919: /* AMD Radeon HD 7500G (Trinity) */
987 case 0x10029990: /* AMD Radeon HD 7520G (Trinity) */
988 case 0x10029991: /* AMD Radeon HD 7540D (Trinity) */
989 case 0x10029992: /* AMD Radeon HD 7420G (Trinity) */
990 case 0x10029993: /* AMD Radeon HD 7480D (Trinity) */
991 case 0x10029994: /* AMD Radeon HD 7400G (Trinity) */
992 case 0x10029995: /* AMD Radeon HD 8450G (Richland) */
993 case 0x10029996: /* AMD Radeon HD 8470D (Richland) */
994 case 0x10029997: /* AMD Radeon HD 8350G (Richland) */
995 case 0x10029998: /* AMD Radeon HD 8370D (Richland) */
996 case 0x10029999: /* AMD Radeon HD 8510G (Richland) */
997 case 0x1002999A: /* AMD Radeon HD 8410G (Richland) */
998 case 0x1002999B: /* AMD Radeon HD 8310G (Richland) */
999 case 0x1002999C: /* AMD Radeon HD 8650D (Richland) */
1000 case 0x1002999D: /* AMD Radeon HD 8550D (Richland) */
1001 case 0x100299A0: /* AMD Radeon HD 7520G (Trinity) */
1002 case 0x100299A2: /* AMD Radeon HD 7420G (Trinity) */
1003 case 0x100299A4: /* AMD Radeon HD 7400G (Trinity) */
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001004 new_vendev = 0x10029901;
Dave Frodincbf3d402012-12-05 08:20:12 -07001005 break;
1006 }
1007
1008 return new_vendev;
1009}