blob: addd40f3c6d261d2e1135bf00d3b7ba3e13d13a5 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Siyuan Wang3e32cc02013-07-09 17:16:20 +08002
3#include <console/console.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpi.h>
6#include <acpi/acpigen.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +08007#include <stdint.h>
8#include <device/device.h>
9#include <device/pci.h>
10#include <device/pci_ids.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080011#include <string.h>
12#include <lib.h>
13#include <cpu/cpu.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080014#include <cpu/x86/lapic.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +020015#include <cpu/amd/msr.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080016#include <cpu/amd/mtrr.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080017#include <Porting.h>
18#include <AGESA.h>
19#include <Options.h>
20#include <Topology.h>
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +020021#include <northbridge/amd/agesa/nb_common.h>
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020022#include <northbridge/amd/agesa/state_machine.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020023#include <northbridge/amd/agesa/agesa_helper.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080024
Kyösti Mälkki113f6702018-05-20 20:12:32 +030025#define MAX_NODE_NUMS MAX_NODES
Siyuan Wang3e32cc02013-07-09 17:16:20 +080026
Siyuan Wang3e32cc02013-07-09 17:16:20 +080027typedef struct dram_base_mask {
28 u32 base; //[47:27] at [28:8]
29 u32 mask; //[47:27] at [28:8] and enable at bit 0
30} dram_base_mask_t;
31
Subrata Banikb1434fc2019-03-15 22:20:41 +053032static unsigned int node_nums;
33static unsigned int sblink;
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030034static struct device *__f0_dev[MAX_NODE_NUMS];
35static struct device *__f1_dev[MAX_NODE_NUMS];
36static struct device *__f2_dev[MAX_NODE_NUMS];
37static struct device *__f4_dev[MAX_NODE_NUMS];
Subrata Banikb1434fc2019-03-15 22:20:41 +053038static unsigned int fx_devs = 0;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080039
40static dram_base_mask_t get_dram_base_mask(u32 nodeid)
41{
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030042 struct device *dev;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080043 dram_base_mask_t d;
44 dev = __f1_dev[0];
45 u32 temp;
46 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
47 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
48 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020049 d.mask |= temp << 21;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080050 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
51 d.mask |= (temp & 1); // enable bit
52 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
53 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020054 d.base |= temp << 21;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080055 return d;
56}
57
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030058static void set_io_addr_reg(struct device *dev, u32 nodeid, u32 linkn, u32 reg,
Siyuan Wang3e32cc02013-07-09 17:16:20 +080059 u32 io_min, u32 io_max)
60{
61 u32 i;
62 u32 tempreg;
63 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020064 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn << 4) | ((io_max&0xf0)<<(12-4)); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020065 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080066 pci_write_config32(__f1_dev[i], reg+4, tempreg);
Elyes HAOUAS27e18012017-06-27 23:14:51 +020067 tempreg = 3 /*| (3 << 4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020068 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080069 pci_write_config32(__f1_dev[i], reg, tempreg);
70}
71
72static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
73{
74 u32 i;
75 u32 tempreg;
76 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020077 tempreg = (nodeid&0xf) | (linkn << 4) | (mmio_max&0xffffff00); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020078 for (i = 0; i < nodes; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080079 pci_write_config32(__f1_dev[i], reg+4, tempreg);
80 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020081 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080082 pci_write_config32(__f1_dev[i], reg, tempreg);
83}
84
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030085static struct device *get_node_pci(u32 nodeid, u32 fn)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080086{
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +020087 return pcidev_on_root(DEV_CDB + nodeid, fn);
Siyuan Wang3e32cc02013-07-09 17:16:20 +080088}
89
90static void get_fx_devs(void)
91{
92 int i;
93 for (i = 0; i < MAX_NODE_NUMS; i++) {
94 __f0_dev[i] = get_node_pci(i, 0);
95 __f1_dev[i] = get_node_pci(i, 1);
96 __f2_dev[i] = get_node_pci(i, 2);
97 __f4_dev[i] = get_node_pci(i, 4);
98 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
99 fx_devs = i+1;
100 }
101 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
102 die("Cannot find 0:0x18.[0|1]\n");
103 }
104 printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs);
105}
106
Subrata Banikb1434fc2019-03-15 22:20:41 +0530107static u32 f1_read_config32(unsigned int reg)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800108{
109 if (fx_devs == 0)
110 get_fx_devs();
111 return pci_read_config32(__f1_dev[0], reg);
112}
113
Subrata Banikb1434fc2019-03-15 22:20:41 +0530114static void f1_write_config32(unsigned int reg, u32 value)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800115{
116 int i;
117 if (fx_devs == 0)
118 get_fx_devs();
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200119 for (i = 0; i < fx_devs; i++) {
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300120 struct device *dev;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800121 dev = __f1_dev[i];
122 if (dev && dev->enabled) {
123 pci_write_config32(dev, reg, value);
124 }
125 }
126}
127
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300128static u32 amdfam16_nodeid(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800129{
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200130 return (dev->path.pci.devfn >> 3) - DEV_CDB;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800131}
132
133static void set_vga_enable_reg(u32 nodeid, u32 linkn)
134{
135 u32 val;
136
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200137 val = 1 | (nodeid << 4) | (linkn << 12);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800138 /* it will routing
139 * (1)mmio 0xa0000:0xbffff
140 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
141 */
142 f1_write_config32(0xf4, val);
143
144}
145
146/**
147 * @return
Elyes HAOUAS99b075a2019-12-30 14:29:31 +0100148 * @retval 2 resource does not exist, usable
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800149 * @retval 0 resource exists, not usable
150 * @retval 1 resource exist, resource has been allocated before
151 */
Subrata Banikb1434fc2019-03-15 22:20:41 +0530152static int reg_useable(unsigned int reg, struct device *goal_dev,
153 unsigned int goal_nodeid, unsigned int goal_link)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800154{
155 struct resource *res;
Subrata Banikb1434fc2019-03-15 22:20:41 +0530156 unsigned int nodeid, link = 0;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800157 int result;
158 res = 0;
159 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300160 struct device *dev;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800161 dev = __f0_dev[nodeid];
162 if (!dev)
163 continue;
164 for (link = 0; !res && (link < 8); link++) {
165 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
166 }
167 }
168 result = 2;
169 if (res) {
170 result = 0;
171 if ((goal_link == (link - 1)) &&
172 (goal_nodeid == (nodeid - 1)) &&
173 (res->flags <= 1)) {
174 result = 1;
175 }
176 }
177 return result;
178}
179
Subrata Banikb1434fc2019-03-15 22:20:41 +0530180static struct resource *amdfam16_find_iopair(struct device *dev,
181 unsigned int nodeid, unsigned int link)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800182{
183 struct resource *resource;
184 u32 free_reg, reg;
185 resource = 0;
186 free_reg = 0;
187 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
188 int result;
189 result = reg_useable(reg, dev, nodeid, link);
190 if (result == 1) {
191 /* I have been allocated this one */
192 break;
193 }
194 else if (result > 1) {
195 /* I have a free register pair */
196 free_reg = reg;
197 }
198 }
199 if (reg > 0xd8) {
200 reg = free_reg; // if no free, the free_reg still be 0
201 }
202
203 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
204
205 return resource;
206}
207
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300208static struct resource *amdfam16_find_mempair(struct device *dev, u32 nodeid, u32 link)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800209{
210 struct resource *resource;
211 u32 free_reg, reg;
212 resource = 0;
213 free_reg = 0;
214 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
215 int result;
216 result = reg_useable(reg, dev, nodeid, link);
217 if (result == 1) {
218 /* I have been allocated this one */
219 break;
220 }
221 else if (result > 1) {
222 /* I have a free register pair */
223 free_reg = reg;
224 }
225 }
226 if (reg > 0xb8) {
227 reg = free_reg;
228 }
229
230 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
231 return resource;
232}
233
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300234static void amdfam16_link_read_bases(struct device *dev, u32 nodeid, u32 link)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800235{
236 struct resource *resource;
237
238 /* Initialize the io space constraints on the current bus */
239 resource = amdfam16_find_iopair(dev, nodeid, link);
240 if (resource) {
241 u32 align;
242 align = log2(HT_IO_HOST_ALIGN);
243 resource->base = 0;
244 resource->size = 0;
245 resource->align = align;
246 resource->gran = align;
247 resource->limit = 0xffffUL;
248 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
249 }
250
251 /* Initialize the prefetchable memory constraints on the current bus */
252 resource = amdfam16_find_mempair(dev, nodeid, link);
253 if (resource) {
254 resource->base = 0;
255 resource->size = 0;
256 resource->align = log2(HT_MEM_HOST_ALIGN);
257 resource->gran = log2(HT_MEM_HOST_ALIGN);
258 resource->limit = 0xffffffffffULL;
259 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
260 resource->flags |= IORESOURCE_BRIDGE;
261 }
262
263 /* Initialize the memory constraints on the current bus */
264 resource = amdfam16_find_mempair(dev, nodeid, link);
265 if (resource) {
266 resource->base = 0;
267 resource->size = 0;
268 resource->align = log2(HT_MEM_HOST_ALIGN);
269 resource->gran = log2(HT_MEM_HOST_ALIGN);
270 resource->limit = 0xffffffffffULL;
271 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
272 }
273
274}
275
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300276static void read_resources(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800277{
278 u32 nodeid;
279 struct bus *link;
280
281 nodeid = amdfam16_nodeid(dev);
282 for (link = dev->link_list; link; link = link->next) {
283 if (link->children) {
284 amdfam16_link_read_bases(dev, nodeid, link->link_num);
285 }
286 }
Edward O'Callaghan66c65322014-11-21 01:43:38 +1100287
288 /*
289 * This MMCONF resource must be reserved in the PCI_DOMAIN.
290 * It is not honored by the coreboot resource allocator if it is in
291 * the APIC_CLUSTER.
292 */
Elyes HAOUAS400ce552018-10-12 10:54:30 +0200293 mmconf_resource(dev, MMIO_CONF_BASE);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800294}
295
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300296static void set_resource(struct device *dev, struct resource *resource, u32 nodeid)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800297{
298 resource_t rbase, rend;
Subrata Banikb1434fc2019-03-15 22:20:41 +0530299 unsigned int reg, link_num;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800300 char buf[50];
301
302 /* Make certain the resource has actually been set */
303 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
304 return;
305 }
306
307 /* If I have already stored this resource don't worry about it */
308 if (resource->flags & IORESOURCE_STORED) {
309 return;
310 }
311
312 /* Only handle PCI memory and IO resources */
313 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
314 return;
315
316 /* Ensure I am actually looking at a resource of function 1 */
317 if ((resource->index & 0xffff) < 0x1000) {
318 return;
319 }
320 /* Get the base address */
321 rbase = resource->base;
322
323 /* Get the limit (rounded up) */
324 rend = resource_end(resource);
325
326 /* Get the register and link */
327 reg = resource->index & 0xfff; // 4k
328 link_num = IOINDEX_LINK(resource->index);
329
330 if (resource->flags & IORESOURCE_IO) {
331 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
332 }
333 else if (resource->flags & IORESOURCE_MEM) {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100334 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 +0800335 }
336 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200337 snprintf(buf, sizeof(buf), " <node %x link %x>",
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800338 nodeid, link_num);
339 report_resource_stored(dev, resource, buf);
340}
341
342/**
343 * I tried to reuse the resource allocation code in set_resource()
344 * but it is too difficult to deal with the resource allocation magic.
345 */
346
Subrata Banikb1434fc2019-03-15 22:20:41 +0530347static void create_vga_resource(struct device *dev, unsigned int nodeid)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800348{
349 struct bus *link;
350
351 /* find out which link the VGA card is connected,
352 * we only deal with the 'first' vga card */
353 for (link = dev->link_list; link; link = link->next) {
354 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800355#if CONFIG(MULTIPLE_VGA_ADAPTERS)
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300356 extern struct device *vga_pri; // the primary vga device, defined in device.c
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800357 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
358 link->secondary,link->subordinate);
359 /* We need to make sure the vga_pri is under the link */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200360 if ((vga_pri->bus->secondary >= link->secondary) &&
361 (vga_pri->bus->secondary <= link->subordinate))
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800362#endif
363 break;
364 }
365 }
366
367 /* no VGA card installed */
368 if (link == NULL)
369 return;
370
371 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
372 set_vga_enable_reg(nodeid, sblink);
373}
374
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300375static void set_resources(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800376{
Subrata Banikb1434fc2019-03-15 22:20:41 +0530377 unsigned int nodeid;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800378 struct bus *bus;
379 struct resource *res;
380
381 /* Find the nodeid */
382 nodeid = amdfam16_nodeid(dev);
383
384 create_vga_resource(dev, nodeid); //TODO: do we need this?
385
386 /* Set each resource we have found */
387 for (res = dev->resource_list; res; res = res->next) {
388 set_resource(dev, res, nodeid);
389 }
390
391 for (bus = dev->link_list; bus; bus = bus->next) {
392 if (bus->children) {
393 assign_resources(bus);
394 }
395 }
396}
397
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100398static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200399{
400 void *addr, *current;
401
402 /* Skip the HEST header. */
403 current = (void *)(hest + 1);
404
405 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
406 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700407 current += acpi_create_hest_error_source(hest, current, 0,
408 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200409
410 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
411 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700412 current += acpi_create_hest_error_source(hest, current, 1,
413 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200414
415 return (unsigned long)current;
416}
417
Furquan Shaikh7536a392020-04-24 21:59:21 -0700418static void northbridge_fill_ssdt_generator(const struct device *device)
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200419{
420 msr_t msr;
421 char pscope[] = "\\_SB.PCI0";
422
423 acpigen_write_scope(pscope);
424 msr = rdmsr(TOP_MEM);
425 acpigen_write_name_dword("TOM1", msr.lo);
426 msr = rdmsr(TOP_MEM2);
427 /*
428 * Since XP only implements parts of ACPI 2.0, we can't use a qword
429 * here.
430 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
431 * slide 22ff.
432 * Shift value right by 20 bit to make it fit into 32bit,
433 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
434 */
435 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
436 acpigen_pop_len();
437}
438
Michał Żygowski9550e972020-03-20 13:56:46 +0100439static void patch_ssdt_processor_scope(acpi_header_t *ssdt)
440{
441 unsigned int len = ssdt->length - sizeof(acpi_header_t);
442 unsigned int i;
443
444 for (i = sizeof(acpi_header_t); i < len; i++) {
445 /* Search for _PR_ scope and replace it with _SB_ */
446 if (*(uint32_t *)((unsigned long)ssdt + i) == 0x5f52505f)
447 *(uint32_t *)((unsigned long)ssdt + i) = 0x5f42535f;
448 }
449 /* Recalculate checksum */
450 ssdt->checksum = 0;
451 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
452}
453
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700454static unsigned long agesa_write_acpi_tables(const 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) {
Michał Żygowski9550e972020-03-20 13:56:46 +0100530 patch_ssdt_processor_scope(ssdt);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200531 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
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800545static struct device_operations northbridge_operations = {
546 .read_resources = read_resources,
547 .set_resources = set_resources,
548 .enable_resources = pci_dev_enable_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200549 .acpi_fill_ssdt = northbridge_fill_ssdt_generator,
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200550 .write_acpi_tables = agesa_write_acpi_tables,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800551};
552
553static const struct pci_driver family16_northbridge __pci_driver = {
554 .ops = &northbridge_operations,
555 .vendor = PCI_VENDOR_ID_AMD,
556 .device = PCI_DEVICE_ID_AMD_16H_MODEL_000F_NB_HT,
557};
558
559static const struct pci_driver family10_northbridge __pci_driver = {
560 .ops = &northbridge_operations,
561 .vendor = PCI_VENDOR_ID_AMD,
562 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
563};
564
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200565static void fam16_finalize(void *chip_info)
566{
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300567 struct device *dev;
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200568 u32 value;
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300569 dev = pcidev_on_root(0, 0); /* clear IoapicSbFeatureEn */
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200570 pci_write_config32(dev, 0xF8, 0);
571 pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */
572
573 /* disable No Snoop */
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300574 dev = pcidev_on_root(1, 1);
Kyösti Mälkki69f6fd42019-01-21 14:19:01 +0200575 if (dev != NULL) {
576 value = pci_read_config32(dev, 0x60);
577 value &= ~(1 << 11);
578 pci_write_config32(dev, 0x60, value);
579 }
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200580}
581
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800582struct chip_operations northbridge_amd_agesa_family16kb_ops = {
583 CHIP_NAME("AMD FAM16 Northbridge")
584 .enable_dev = 0,
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200585 .final = fam16_finalize,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800586};
587
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300588static void domain_read_resources(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800589{
Subrata Banikb1434fc2019-03-15 22:20:41 +0530590 unsigned int reg;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800591
592 /* Find the already assigned resource pairs */
593 get_fx_devs();
594 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
595 u32 base, limit;
596 base = f1_read_config32(reg);
597 limit = f1_read_config32(reg + 0x04);
598 /* Is this register allocated? */
599 if ((base & 3) != 0) {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530600 unsigned int nodeid, reg_link;
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300601 struct device *reg_dev;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200602 if (reg < 0xc0) { // mmio
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800603 nodeid = (limit & 0xf) + (base&0x30);
604 } else { // io
605 nodeid = (limit & 0xf) + ((base>>4)&0x30);
606 }
607 reg_link = (limit >> 4) & 7;
608 reg_dev = __f0_dev[nodeid];
609 if (reg_dev) {
610 /* Reserve the resource */
611 struct resource *res;
612 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
613 if (res) {
614 res->flags = 1;
615 }
616 }
617 }
618 }
619 /* FIXME: do we need to check extend conf space?
620 I don't believe that much preset value */
621
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800622 pci_domain_read_resources(dev);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800623}
624
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800625#if CONFIG_HW_MEM_HOLE_SIZEK != 0
626struct hw_mem_hole_info {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530627 unsigned int hole_startk;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800628 int node_id;
629};
630static struct hw_mem_hole_info get_hw_mem_hole_info(void)
631{
632 struct hw_mem_hole_info mem_hole;
633 int i;
634 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
635 mem_hole.node_id = -1;
636 for (i = 0; i < node_nums; i++) {
637 dram_base_mask_t d;
638 u32 hole;
639 d = get_dram_base_mask(i);
640 if (!(d.mask & 1)) continue; // no memory on this node
641 hole = pci_read_config32(__f1_dev[i], 0xf0);
642 if (hole & 2) { // we find the hole
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200643 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800644 mem_hole.node_id = i; // record the node No with hole
645 break; // only one hole
646 }
647 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300648
649 /* We need to double check if there is special set on base reg and limit reg
650 * are not continuous instead of hole, it will find out its hole_startk.
651 */
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800652 if (mem_hole.node_id == -1) {
653 resource_t limitk_pri = 0;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200654 for (i = 0; i < node_nums; i++) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800655 dram_base_mask_t d;
656 resource_t base_k, limit_k;
657 d = get_dram_base_mask(i);
658 if (!(d.base & 1)) continue;
659 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
660 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
661 if (limitk_pri != base_k) { // we find the hole
Martin Roth468d02c2019-10-23 21:44:42 -0600662 mem_hole.hole_startk = (unsigned int)limitk_pri; // must beblow 4G
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800663 mem_hole.node_id = i;
664 break; //only one hole
665 }
666 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
667 limitk_pri = limit_k;
668 }
669 }
670 return mem_hole;
671}
672#endif
673
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300674static void domain_set_resources(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800675{
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800676 unsigned long mmio_basek;
677 u32 pci_tolm;
678 int i, idx;
679 struct bus *link;
680#if CONFIG_HW_MEM_HOLE_SIZEK != 0
681 struct hw_mem_hole_info mem_hole;
682 u32 reset_memhole = 1;
683#endif
684
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800685 pci_tolm = 0xffffffffUL;
686 for (link = dev->link_list; link; link = link->next) {
687 pci_tolm = find_pci_tolm(link);
688 }
689
690 // FIXME handle interleaved nodes. If you fix this here, please fix
691 // amdk8, too.
692 mmio_basek = pci_tolm >> 10;
693 /* Round mmio_basek to something the processor can support */
694 mmio_basek &= ~((1 << 6) -1);
695
696 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
697 // MMIO hole. If you fix this here, please fix amdk8, too.
698 /* Round the mmio hole to 64M */
699 mmio_basek &= ~((64*1024) - 1);
700
701#if CONFIG_HW_MEM_HOLE_SIZEK != 0
702 /* if the hw mem hole is already set in raminit stage, here we will compare
703 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
704 * use hole_basek as mmio_basek and we don't need to reset hole.
705 * otherwise We reset the hole to the mmio_basek
706 */
707
708 mem_hole = get_hw_mem_hole_info();
709
710 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
711 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
712 mmio_basek = mem_hole.hole_startk;
713 reset_memhole = 0;
714 }
715#endif
716
717 idx = 0x10;
718 for (i = 0; i < node_nums; i++) {
719 dram_base_mask_t d;
720 resource_t basek, limitk, sizek; // 4 1T
721
722 d = get_dram_base_mask(i);
723
724 if (!(d.mask & 1)) continue;
725 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100726 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800727
728 sizek = limitk - basek;
729
730 /* see if we need a hole from 0xa0000 to 0xbffff */
731 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
732 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
733 idx += 0x10;
734 basek = (8*64)+(16*16);
735 sizek = limitk - ((8*64)+(16*16));
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800736 }
737
738 //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk);
739
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300740 /* split the region to accommodate pci memory space */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200741 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800742 if (basek <= mmio_basek) {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530743 unsigned int pre_sizek;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800744 pre_sizek = mmio_basek - basek;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200745 if (pre_sizek > 0) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800746 ram_resource(dev, (idx | i), basek, pre_sizek);
747 idx += 0x10;
748 sizek -= pre_sizek;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800749 }
750 basek = mmio_basek;
751 }
752 if ((basek + sizek) <= 4*1024*1024) {
753 sizek = 0;
754 }
755 else {
756 uint64_t topmem2 = bsp_topmem2();
757 basek = 4*1024*1024;
758 sizek = topmem2/1024 - basek;
759 }
760 }
761
762 ram_resource(dev, (idx | i), basek, sizek);
763 idx += 0x10;
764 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
765 i, mmio_basek, basek, limitk);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800766 }
767
Kyösti Mälkki61be3602017-04-15 20:07:53 +0300768 add_uma_resource_below_tolm(dev, 7);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800769
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200770 for (link = dev->link_list; link; link = link->next) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800771 if (link->children) {
772 assign_resources(link);
773 }
774 }
775}
776
Kevin Cody-Little06d23232018-05-09 14:22:15 -0400777static const char *domain_acpi_name(const struct device *dev)
778{
779 if (dev->path.type == DEVICE_PATH_DOMAIN)
780 return "PCI0";
781
782 return NULL;
783}
784
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800785static struct device_operations pci_domain_ops = {
786 .read_resources = domain_read_resources,
787 .set_resources = domain_set_resources,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800788 .scan_bus = pci_domain_scan_bus,
Kevin Cody-Little06d23232018-05-09 14:22:15 -0400789 .acpi_name = domain_acpi_name,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800790};
791
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300792static void sysconf_init(struct device *dev) // first node
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800793{
794 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
795 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
796}
797
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300798static void cpu_bus_scan(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800799{
800 struct bus *cpu_bus;
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300801 struct device *dev_mc;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800802 int i,j;
803 int coreid_bits;
804 int core_max = 0;
Subrata Banikb1434fc2019-03-15 22:20:41 +0530805 unsigned int ApicIdCoreIdSize;
806 unsigned int core_nums;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800807 int siblings = 0;
808 unsigned int family;
809
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200810 dev_mc = pcidev_on_root(DEV_CDB, 0);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800811 if (!dev_mc) {
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200812 printk(BIOS_ERR, "0:%02x.0 not found", DEV_CDB);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800813 die("");
814 }
815 sysconf_init(dev_mc);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800816
817 /* Get Max Number of cores(MNC) */
Kyösti Mälkkid41feed2017-09-24 16:23:57 +0300818 coreid_bits = (cpuid_ecx(0x80000008) & 0x0000F000) >> 12;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800819 core_max = 1 << (coreid_bits & 0x000F); //mnc
820
821 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
822 if (ApicIdCoreIdSize) {
823 core_nums = (1 << ApicIdCoreIdSize) - 1;
824 } else {
825 core_nums = 3; //quad core
826 }
827
828 /* Find which cpus are present */
829 cpu_bus = dev->link_list;
830 for (i = 0; i < node_nums; i++) {
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300831 struct device *cdb_dev;
Subrata Banikb1434fc2019-03-15 22:20:41 +0530832 unsigned int devn;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800833 struct bus *pbus;
834
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200835 devn = DEV_CDB + i;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800836 pbus = dev_mc->bus;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800837
838 /* Find the cpu's pci device */
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300839 cdb_dev = pcidev_on_root(devn, 0);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800840 if (!cdb_dev) {
841 /* If I am probing things in a weird order
842 * ensure all of the cpu's pci devices are found.
843 */
844 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200845 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800846 cdb_dev = pci_probe_dev(NULL, pbus,
847 PCI_DEVFN(devn, fn));
848 }
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300849 cdb_dev = pcidev_on_root(devn, 0);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800850 } else {
851 /* Ok, We need to set the links for that device.
852 * otherwise the device under it will not be scanned
853 */
Kyösti Mälkki2a2d6132015-02-04 13:25:37 +0200854 add_more_links(cdb_dev, 4);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800855 }
856
857 family = cpuid_eax(1);
858 family = (family >> 20) & 0xFF;
859 if (family == 1) { //f10
860 u32 dword;
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300861 cdb_dev = pcidev_on_root(devn, 3);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800862 dword = pci_read_config32(cdb_dev, 0xe8);
863 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
864 } else if (family == 7) {//f16
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300865 cdb_dev = pcidev_on_root(devn, 5);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800866 if (cdb_dev && cdb_dev->enabled) {
867 siblings = pci_read_config32(cdb_dev, 0x84);
868 siblings &= 0xFF;
869 }
870 } else {
871 siblings = 0; //default one core
872 }
873 int enable_node = cdb_dev && cdb_dev->enabled;
874 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
875 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
876
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200877 for (j = 0; j <= siblings; j++) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800878 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
879 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
880 u32 lapicid_start = 0;
881
882 /*
883 * APIC ID calucation is tightly coupled with AGESA v5 code.
884 * This calculation MUST match the assignment calculation done
885 * in LocalApicInitializationAtEarly() function.
886 * And reference GetLocalApicIdForCore()
887 *
Elyes HAOUASa5b0bc42020-02-20 20:04:29 +0100888 * Apply APIC enumeration rules
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800889 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
890 * put the local-APICs at m..z
891 *
892 * This is needed because many IO-APIC devices only have 4 bits
893 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200894 */
Kyösti Mälkki50036322016-05-18 13:35:21 +0300895
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200896 u8 plat_num_io_apics = 3; /* FIXME */
Kyösti Mälkki50036322016-05-18 13:35:21 +0300897
898 if ((node_nums * core_max) + plat_num_io_apics >= 0x10) {
899 lapicid_start = (plat_num_io_apics - 1) / core_max;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800900 lapicid_start = (lapicid_start + 1) * core_max;
901 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
902 }
903 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
904 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
905 i, j, apic_id);
906
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300907 struct device *cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800908 if (cpu)
909 amd_cpu_topology(cpu, i, j);
910 } //j
911 }
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800912}
913
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300914static void cpu_bus_init(struct device *dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800915{
916 initialize_cpus(dev->link_list);
917}
918
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800919static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200920 .read_resources = noop_read_resources,
921 .set_resources = noop_set_resources,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800922 .init = cpu_bus_init,
923 .scan_bus = cpu_bus_scan,
924};
925
926static void root_complex_enable_dev(struct device *dev)
927{
928 static int done = 0;
929
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800930 if (!done) {
931 setup_bsp_ramtop();
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800932 done = 1;
933 }
934
935 /* Set the operations if it is a special bus type */
936 if (dev->path.type == DEVICE_PATH_DOMAIN) {
937 dev->ops = &pci_domain_ops;
938 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
939 dev->ops = &cpu_bus_ops;
940 }
941}
942
943struct chip_operations northbridge_amd_agesa_family16kb_root_complex_ops = {
944 CHIP_NAME("AMD FAM16 Root Complex")
945 .enable_dev = root_complex_enable_dev,
946};
Bruce Griffith76db07e2013-07-07 02:06:53 -0600947
948/*********************************************************************
949 * Change the vendor / device IDs to match the generic VBIOS header. *
950 *********************************************************************/
951u32 map_oprom_vendev(u32 vendev)
952{
953 u32 new_vendev = vendev;
954
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +0100955 switch (vendev) {
Bruce Griffith76db07e2013-07-07 02:06:53 -0600956 case 0x10029830:
957 case 0x10029831:
958 case 0x10029832:
959 case 0x10029833:
960 case 0x10029834:
961 case 0x10029835:
962 case 0x10029836:
963 case 0x10029837:
964 case 0x10029838:
965 case 0x10029839:
966 case 0x1002983A:
967 case 0x1002983D:
968 new_vendev = 0x10029830; // This is the default value in AMD-generated VBIOS
969 break;
970 default:
971 break;
972 }
973
974 if (vendev != new_vendev)
975 printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev);
976
977 return new_vendev;
978}