blob: a1d345728a9c2689b4ae8e54de42aac14623a3d4 [file] [log] [blame]
Frank Vibrans39fca802011-02-14 18:35:15 +00001/*
2 * This file is part of the coreboot project.
3 *
Frank Vibrans39fca802011-02-14 18:35:15 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Frank Vibrans39fca802011-02-14 18:35:15 +000013 */
14
15#include <console/console.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020016#include <device/pci_ops.h>
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +030017#include <arch/acpi.h>
Kyösti Mälkki68a83df2014-11-26 09:51:14 +020018#include <arch/acpigen.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000019#include <stdint.h>
20#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
23#include <device/hypertransport.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000024#include <string.h>
Ronald G. Minnich5079a0d2012-11-27 11:32:38 -080025#include <lib.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000026#include <cpu/cpu.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000027#include <cpu/x86/lapic.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +020028#include <cpu/amd/msr.h>
Kyösti Mälkki55fff9302012-07-11 08:02:39 +030029#include <cpu/amd/mtrr.h>
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +020030#include <northbridge/amd/agesa/nb_common.h>
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020031#include <northbridge/amd/agesa/state_machine.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020032#include <northbridge/amd/agesa/agesa_helper.h>
Kerry Shefeed3292011-08-18 18:03:44 +080033#include <sb_cimx.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000034
Frank Vibrans39fca802011-02-14 18:35:15 +000035#define FX_DEVS 1
36
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030037static struct device *__f0_dev[FX_DEVS];
38static struct device *__f1_dev[FX_DEVS];
39static struct device *__f2_dev[FX_DEVS];
40static struct device *__f4_dev[FX_DEVS];
Subrata Banikb1434fc2019-03-15 22:20:41 +053041static unsigned int fx_devs = 0;
Frank Vibrans39fca802011-02-14 18:35:15 +000042
Kyösti Mälkki2b218e32019-01-15 11:14:28 +020043
44struct dram_base_mask_t {
45 u32 base; //[47:27] at [28:8]
46 u32 mask; //[47:27] at [28:8] and enable at bit 0
47};
48
49static struct dram_base_mask_t get_dram_base_mask(u32 nodeid)
50{
51 struct device *dev;
52 struct dram_base_mask_t d;
Kyösti Mälkki2b218e32019-01-15 11:14:28 +020053 dev = __f1_dev[0];
Kyösti Mälkki2b218e32019-01-15 11:14:28 +020054
55 u32 temp;
56 temp = pci_read_config32(dev, 0x44); //[39:24] at [31:16]
57 d.mask = (temp & 0xffff0000); // mask out DramMask [26:24] too
58
59 temp = pci_read_config32(dev, 0x40); //[35:24] at [27:16]
60 d.mask |= (temp & 1); // read enable bit
61
62 d.base = (temp & 0x0fff0000); // mask out DramBase [26:24) too
63
64 return d;
65}
66
67static u32 get_io_addr_index(u32 nodeid, u32 linkn)
68{
69 return 0;
70}
71
72static u32 get_mmio_addr_index(u32 nodeid, u32 linkn)
73{
74 return 0;
75}
76
77static void set_io_addr_reg(struct device *dev, u32 nodeid, u32 linkn, u32 reg,
78 u32 io_min, u32 io_max)
79{
80
81 u32 tempreg;
82 /* io range allocation */
83 tempreg = (nodeid & 0xf) | ((nodeid & 0x30) << (8 - 4)) | (linkn << 4) |
84 ((io_max & 0xf0) << (12 - 4)); //limit
85 pci_write_config32(__f1_dev[0], reg+4, tempreg);
86
87 tempreg = 3 | ((io_min & 0xf0) << (12 - 4)); //base :ISA and VGA ?
88 pci_write_config32(__f1_dev[0], reg, tempreg);
89}
90
91static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index,
92 u32 mmio_min, u32 mmio_max, u32 nodes)
93{
94
95 u32 tempreg;
96 /* io range allocation */
97 tempreg = (nodeid & 0xf) | (linkn << 4) | (mmio_max & 0xffffff00);
98 pci_write_config32(__f1_dev[0], reg + 4, tempreg);
99 tempreg = 3 | (nodeid & 0x30) | (mmio_min & 0xffffff00);
100 pci_write_config32(__f1_dev[0], reg, tempreg);
101}
102
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300103static struct device *get_node_pci(u32 nodeid, u32 fn)
Frank Vibrans39fca802011-02-14 18:35:15 +0000104{
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200105 return pcidev_on_root(DEV_CDB + nodeid, fn);
Frank Vibrans39fca802011-02-14 18:35:15 +0000106}
107
Frank Vibrans39fca802011-02-14 18:35:15 +0000108static void get_fx_devs(void)
109{
Marc Jones8d595692012-03-15 12:55:26 -0600110 int i;
111 for (i = 0; i < FX_DEVS; i++) {
112 __f0_dev[i] = get_node_pci(i, 0);
113 __f1_dev[i] = get_node_pci(i, 1);
114 __f2_dev[i] = get_node_pci(i, 2);
115 __f4_dev[i] = get_node_pci(i, 4);
116 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
117 fx_devs = i + 1;
118 }
119 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
120 die("Cannot find 0:0x18.[0|1]\n");
121 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000122}
123
Subrata Banikb1434fc2019-03-15 22:20:41 +0530124static u32 f1_read_config32(unsigned int reg)
Frank Vibrans39fca802011-02-14 18:35:15 +0000125{
Marc Jones8d595692012-03-15 12:55:26 -0600126 if (fx_devs == 0)
127 get_fx_devs();
128 return pci_read_config32(__f1_dev[0], reg);
Frank Vibrans39fca802011-02-14 18:35:15 +0000129}
130
Subrata Banikb1434fc2019-03-15 22:20:41 +0530131static void f1_write_config32(unsigned int reg, u32 value)
Frank Vibrans39fca802011-02-14 18:35:15 +0000132{
Marc Jones8d595692012-03-15 12:55:26 -0600133 int i;
134 if (fx_devs == 0)
135 get_fx_devs();
136 for (i = 0; i < fx_devs; i++) {
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200137 struct device *dev;
Marc Jones8d595692012-03-15 12:55:26 -0600138 dev = __f1_dev[i];
139 if (dev && dev->enabled) {
140 pci_write_config32(dev, reg, value);
141 }
142 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000143}
144
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200145static u32 amdfam14_nodeid(struct device *dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000146{
Kyösti Mälkki3d3152e2019-01-10 09:05:30 +0200147 return (dev->path.pci.devfn >> 3) - DEV_CDB;
Frank Vibrans39fca802011-02-14 18:35:15 +0000148}
149
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200150static void northbridge_init(struct device *dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000151{
Marc Jones8d595692012-03-15 12:55:26 -0600152 printk(BIOS_DEBUG, "Northbridge init\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000153}
154
Frank Vibrans39fca802011-02-14 18:35:15 +0000155static void set_vga_enable_reg(u32 nodeid, u32 linkn)
156{
Marc Jones8d595692012-03-15 12:55:26 -0600157 u32 val;
Frank Vibrans39fca802011-02-14 18:35:15 +0000158
Marc Jones8d595692012-03-15 12:55:26 -0600159 val = 1 | (nodeid << 4) | (linkn << 12);
160 /* it will routing (1)mmio 0xa0000:0xbffff (2) io 0x3b0:0x3bb,
161 0x3c0:0x3df */
162 f1_write_config32(0xf4, val);
Frank Vibrans39fca802011-02-14 18:35:15 +0000163
164}
165
Subrata Banikb1434fc2019-03-15 22:20:41 +0530166static int reg_useable(unsigned int reg, struct device *goal_dev,
167 unsigned int goal_nodeid, unsigned int goal_link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000168{
Marc Jones8d595692012-03-15 12:55:26 -0600169 struct resource *res;
Subrata Banikb1434fc2019-03-15 22:20:41 +0530170 unsigned int nodeid, link = 0;
Marc Jones8d595692012-03-15 12:55:26 -0600171 int result;
172 res = 0;
173 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200174 struct device *dev;
Marc Jones8d595692012-03-15 12:55:26 -0600175 dev = __f0_dev[nodeid];
176 if (!dev)
177 continue;
178 for (link = 0; !res && (link < 8); link++) {
179 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
180 }
181 }
182 result = 2;
183 if (res) {
184 result = 0;
185 if ((goal_link == (link - 1)) &&
186 (goal_nodeid == (nodeid - 1)) && (res->flags <= 1)) {
187 result = 1;
188 }
189 }
190 return result;
Frank Vibrans39fca802011-02-14 18:35:15 +0000191}
192
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200193static struct resource *amdfam14_find_iopair(struct device *dev,
Subrata Banikb1434fc2019-03-15 22:20:41 +0530194 unsigned int nodeid, unsigned int link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000195{
Marc Jones8d595692012-03-15 12:55:26 -0600196 struct resource *resource;
197 u32 result, reg;
198 resource = 0;
199 reg = 0;
200 result = reg_useable(0xc0, dev, nodeid, link);
201 if (result >= 1) {
202 /* I have been allocated this one */
203 reg = 0xc0;
204 }
205 /* Ext conf space */
206 if (!reg) {
207 /* Because of Extend conf space, we will never run out of reg,
Elyes HAOUASa342f392018-10-17 10:56:26 +0200208 * but we need one index to differ them. So,same node and same
Marc Jones8d595692012-03-15 12:55:26 -0600209 * link can have multi range
210 */
211 u32 index = get_io_addr_index(nodeid, link);
212 reg = 0x110 + (index << 24) + (4 << 20); // index could be 0, 255
213 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000214
Marc Jones8d595692012-03-15 12:55:26 -0600215 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
Frank Vibrans39fca802011-02-14 18:35:15 +0000216
Marc Jones8d595692012-03-15 12:55:26 -0600217 return resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000218}
219
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200220static struct resource *amdfam14_find_mempair(struct device *dev, u32 nodeid,
Marc Jones8d595692012-03-15 12:55:26 -0600221 u32 link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000222{
Marc Jones8d595692012-03-15 12:55:26 -0600223 struct resource *resource;
224 u32 free_reg, reg;
225 resource = 0;
226 free_reg = 0;
227 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
228 int result;
229 result = reg_useable(reg, dev, nodeid, link);
230 if (result == 1) {
231 /* I have been allocated this one */
232 break;
233 } else if (result > 1) {
234 /* I have a free register pair */
235 free_reg = reg;
236 }
237 }
238 if (reg > 0xb8) {
239 reg = free_reg;
240 }
241 /* Ext conf space */
242 if (!reg) {
243 /* Because of Extend conf space, we will never run out of reg,
Elyes HAOUASa342f392018-10-17 10:56:26 +0200244 * but we need one index to differ them. So,same node and same
Marc Jones8d595692012-03-15 12:55:26 -0600245 * link can have multi range
246 */
247 u32 index = get_mmio_addr_index(nodeid, link);
248 reg = 0x110 + (index << 24) + (6 << 20); // index could be 0, 63
Frank Vibrans39fca802011-02-14 18:35:15 +0000249
Marc Jones8d595692012-03-15 12:55:26 -0600250 }
251 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
252 return resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000253}
254
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200255static void amdfam14_link_read_bases(struct device *dev, u32 nodeid, u32 link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000256{
Marc Jones8d595692012-03-15 12:55:26 -0600257 struct resource *resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000258
Marc Jones8d595692012-03-15 12:55:26 -0600259 /* Initialize the io space constraints on the current bus */
260 resource = amdfam14_find_iopair(dev, nodeid, link);
261 if (resource) {
262 u32 align;
Kyösti Mälkkiac7402d2014-12-14 08:30:17 +0200263 align = log2(HT_IO_HOST_ALIGN);
Marc Jones8d595692012-03-15 12:55:26 -0600264 resource->base = 0;
265 resource->size = 0;
266 resource->align = align;
267 resource->gran = align;
268 resource->limit = 0xffffUL;
269 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
270 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000271
Marc Jones8d595692012-03-15 12:55:26 -0600272 /* Initialize the prefetchable memory constraints on the current bus */
273 resource = amdfam14_find_mempair(dev, nodeid, link);
274 if (resource) {
275 resource->base = 0;
276 resource->size = 0;
277 resource->align = log2(HT_MEM_HOST_ALIGN);
278 resource->gran = log2(HT_MEM_HOST_ALIGN);
279 resource->limit = 0xffffffffffULL;
280 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
281 resource->flags |= IORESOURCE_BRIDGE;
Marc Jones8d595692012-03-15 12:55:26 -0600282 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000283
Marc Jones8d595692012-03-15 12:55:26 -0600284 /* Initialize the memory constraints on the current bus */
285 resource = amdfam14_find_mempair(dev, nodeid, link);
286 if (resource) {
287 resource->base = 0;
288 resource->size = 0;
289 resource->align = log2(HT_MEM_HOST_ALIGN);
290 resource->gran = log2(HT_MEM_HOST_ALIGN);
291 resource->limit = 0xffffffffffULL;
292 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
Marc Jones8d595692012-03-15 12:55:26 -0600293 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000294}
295
296static u32 my_find_pci_tolm(struct bus *bus, u32 tolm)
297{
Marc Jones8d595692012-03-15 12:55:26 -0600298 struct resource *min;
299 min = 0;
300 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test,
301 &min);
302 if (min && tolm > min->base) {
303 tolm = min->base;
304 }
305 return tolm;
Frank Vibrans39fca802011-02-14 18:35:15 +0000306}
307
308#if CONFIG_HW_MEM_HOLE_SIZEK != 0
309
310struct hw_mem_hole_info {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530311 unsigned int hole_startk;
Marc Jones8d595692012-03-15 12:55:26 -0600312 int node_id;
Frank Vibrans39fca802011-02-14 18:35:15 +0000313};
314
315static struct hw_mem_hole_info get_hw_mem_hole_info(void)
316{
Marc Jones8d595692012-03-15 12:55:26 -0600317 struct hw_mem_hole_info mem_hole;
Frank Vibrans39fca802011-02-14 18:35:15 +0000318
Marc Jones8d595692012-03-15 12:55:26 -0600319 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
320 mem_hole.node_id = -1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000321
Marc Jones8d595692012-03-15 12:55:26 -0600322 struct dram_base_mask_t d;
323 u32 hole;
324 d = get_dram_base_mask(0);
325 if (d.mask & 1) {
326 hole = pci_read_config32(__f1_dev[0], 0xf0);
327 if (hole & 1) { // we find the hole
328 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
329 mem_hole.node_id = 0; // record the node No with hole
330 }
331 }
Marc Jones8d595692012-03-15 12:55:26 -0600332 return mem_hole;
Frank Vibrans39fca802011-02-14 18:35:15 +0000333}
334#endif
335
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200336static void nb_read_resources(struct device *dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000337{
Marc Jones8d595692012-03-15 12:55:26 -0600338 u32 nodeid;
339 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000340
Mike Loptien58089e82013-01-29 15:45:09 -0700341 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000342
Marc Jones8d595692012-03-15 12:55:26 -0600343 nodeid = amdfam14_nodeid(dev);
344 for (link = dev->link_list; link; link = link->next) {
345 if (link->children) {
346 amdfam14_link_read_bases(dev, nodeid, link->link_num);
347 }
348 }
Marc Jonesd5c998b2013-01-16 17:14:24 -0700349
350 /*
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800351 * This MMCONF resource must be reserved in the PCI domain.
Marc Jonesd5c998b2013-01-16 17:14:24 -0700352 * It is not honored by the coreboot resource allocator if it is in
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800353 * the CPU_CLUSTER.
Marc Jonesd5c998b2013-01-16 17:14:24 -0700354 */
Elyes HAOUAS400ce552018-10-12 10:54:30 +0200355 mmconf_resource(dev, MMIO_CONF_BASE);
Frank Vibrans39fca802011-02-14 18:35:15 +0000356}
357
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200358static void set_resource(struct device *dev, struct resource *resource,
359 u32 nodeid)
Frank Vibrans39fca802011-02-14 18:35:15 +0000360{
Marc Jones8d595692012-03-15 12:55:26 -0600361 resource_t rbase, rend;
Subrata Banikb1434fc2019-03-15 22:20:41 +0530362 unsigned int reg, link_num;
Marc Jones8d595692012-03-15 12:55:26 -0600363 char buf[50];
Frank Vibrans39fca802011-02-14 18:35:15 +0000364
Mike Loptien58089e82013-01-29 15:45:09 -0700365 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000366
Marc Jones8d595692012-03-15 12:55:26 -0600367 /* Make certain the resource has actually been set */
368 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
369 return;
370 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000371
Marc Jones8d595692012-03-15 12:55:26 -0600372 /* If I have already stored this resource don't worry about it */
373 if (resource->flags & IORESOURCE_STORED) {
374 return;
375 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000376
Marc Jones8d595692012-03-15 12:55:26 -0600377 /* Only handle PCI memory and IO resources */
378 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
379 return;
Frank Vibrans39fca802011-02-14 18:35:15 +0000380
Marc Jones8d595692012-03-15 12:55:26 -0600381 /* Ensure I am actually looking at a resource of function 1 */
382 if ((resource->index & 0xffff) < 0x1000) {
383 return;
384 }
385 /* Get the base address */
386 rbase = resource->base;
Frank Vibrans39fca802011-02-14 18:35:15 +0000387
Marc Jones8d595692012-03-15 12:55:26 -0600388 /* Get the limit (rounded up) */
389 rend = resource_end(resource);
Frank Vibrans39fca802011-02-14 18:35:15 +0000390
Marc Jones8d595692012-03-15 12:55:26 -0600391 /* Get the register and link */
392 reg = resource->index & 0xfff; // 4k
393 link_num = IOINDEX_LINK(resource->index);
Frank Vibrans39fca802011-02-14 18:35:15 +0000394
Marc Jones8d595692012-03-15 12:55:26 -0600395 if (resource->flags & IORESOURCE_IO) {
396 set_io_addr_reg(dev, nodeid, link_num, reg, rbase >> 8,
397 rend >> 8);
398 } else if (resource->flags & IORESOURCE_MEM) {
399 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >> 24),
400 rbase >> 8, rend >> 8, 1); // [39:8]
401 }
402 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200403 snprintf(buf, sizeof(buf), " <node %x link %x>", nodeid, link_num);
Marc Jones8d595692012-03-15 12:55:26 -0600404 report_resource_stored(dev, resource, buf);
Frank Vibrans39fca802011-02-14 18:35:15 +0000405}
406
Julius Wernercd49cce2019-03-05 16:53:33 -0800407#if CONFIG(CONSOLE_VGA_MULTI)
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300408extern struct device *vga_pri; // the primary vga device, defined in device.c
Frank Vibrans39fca802011-02-14 18:35:15 +0000409#endif
410
Subrata Banikb1434fc2019-03-15 22:20:41 +0530411static void create_vga_resource(struct device *dev, unsigned int nodeid)
Frank Vibrans39fca802011-02-14 18:35:15 +0000412{
Marc Jones8d595692012-03-15 12:55:26 -0600413 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000414
Mike Loptien58089e82013-01-29 15:45:09 -0700415 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000416
Marc Jones8d595692012-03-15 12:55:26 -0600417 /* find out which link the VGA card is connected,
418 * we only deal with the 'first' vga card */
419 for (link = dev->link_list; link; link = link->next) {
420 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800421#if CONFIG(CONSOLE_VGA_MULTI)
Marc Jones8d595692012-03-15 12:55:26 -0600422 printk(BIOS_DEBUG,
423 "VGA: vga_pri bus num = %d bus range [%d,%d]\n",
424 vga_pri->bus->secondary, link->secondary,
425 link->subordinate);
426 /* We need to make sure the vga_pri is under the link */
427 if ((vga_pri->bus->secondary >= link->secondary) &&
428 (vga_pri->bus->secondary <= link->subordinate))
Frank Vibrans39fca802011-02-14 18:35:15 +0000429#endif
Marc Jones8d595692012-03-15 12:55:26 -0600430 break;
431 }
432 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000433
Marc Jones8d595692012-03-15 12:55:26 -0600434 /* no VGA card installed */
435 if (link == NULL)
436 return;
Frank Vibrans39fca802011-02-14 18:35:15 +0000437
Marc Jones8d595692012-03-15 12:55:26 -0600438 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n",
439 dev_path(dev), nodeid, link->link_num);
440 set_vga_enable_reg(nodeid, link->link_num);
Frank Vibrans39fca802011-02-14 18:35:15 +0000441}
442
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200443static void nb_set_resources(struct device *dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000444{
Subrata Banikb1434fc2019-03-15 22:20:41 +0530445 unsigned int nodeid;
Marc Jones8d595692012-03-15 12:55:26 -0600446 struct bus *bus;
447 struct resource *res;
Frank Vibrans39fca802011-02-14 18:35:15 +0000448
Mike Loptien58089e82013-01-29 15:45:09 -0700449 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
efdesign9805a89ab2011-06-20 17:38:49 -0700450
Marc Jones8d595692012-03-15 12:55:26 -0600451 /* Find the nodeid */
452 nodeid = amdfam14_nodeid(dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000453
Marc Jones8d595692012-03-15 12:55:26 -0600454 create_vga_resource(dev, nodeid);
Frank Vibrans39fca802011-02-14 18:35:15 +0000455
Marc Jones8d595692012-03-15 12:55:26 -0600456 /* Set each resource we have found */
457 for (res = dev->resource_list; res; res = res->next) {
458 set_resource(dev, res, nodeid);
459 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000460
Marc Jones8d595692012-03-15 12:55:26 -0600461 for (bus = dev->link_list; bus; bus = bus->next) {
462 if (bus->children) {
463 assign_resources(bus);
464 }
465 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000466}
467
Frank Vibrans39fca802011-02-14 18:35:15 +0000468/* Domain/Root Complex related code */
469
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200470static void domain_read_resources(struct device *dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000471{
Subrata Banikb1434fc2019-03-15 22:20:41 +0530472 unsigned int reg;
Frank Vibrans39fca802011-02-14 18:35:15 +0000473
Mike Loptien58089e82013-01-29 15:45:09 -0700474 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000475
Marc Jones8d595692012-03-15 12:55:26 -0600476 /* Find the already assigned resource pairs */
477 get_fx_devs();
478 for (reg = 0x80; reg <= 0xc0; reg += 0x08) {
479 u32 base, limit;
480 base = f1_read_config32(reg);
481 limit = f1_read_config32(reg + 0x04);
482 /* Is this register allocated? */
483 if ((base & 3) != 0) {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530484 unsigned int nodeid, reg_link;
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200485 struct device *reg_dev;
Marc Jones8d595692012-03-15 12:55:26 -0600486 if (reg < 0xc0) { // mmio
487 nodeid = (limit & 0xf) + (base & 0x30);
488 } else { // io
489 nodeid = (limit & 0xf) + ((base >> 4) & 0x30);
490 }
491 reg_link = (limit >> 4) & 7;
492 reg_dev = __f0_dev[nodeid];
493 if (reg_dev) {
494 /* Reserve the resource */
495 struct resource *res;
496 res =
497 new_resource(reg_dev,
498 IOINDEX(0x1000 + reg,
499 reg_link));
500 if (res) {
501 res->flags = 1;
502 }
503 }
504 }
505 }
506 /* FIXME: do we need to check extend conf space?
507 I don't believe that much preset value */
Frank Vibrans39fca802011-02-14 18:35:15 +0000508
Marc Jones8d595692012-03-15 12:55:26 -0600509 pci_domain_read_resources(dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000510}
511
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200512static void domain_set_resources(struct device *dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000513{
Mike Loptien58089e82013-01-29 15:45:09 -0700514 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Stefan Reinauer29e65482015-06-18 01:18:09 -0700515 printk(BIOS_DEBUG, " amsr - incoming dev = %p\n", dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000516
Marc Jones8d595692012-03-15 12:55:26 -0600517 unsigned long mmio_basek;
518 u32 pci_tolm;
519 int idx;
520 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000521#if CONFIG_HW_MEM_HOLE_SIZEK != 0
Marc Jones8d595692012-03-15 12:55:26 -0600522 struct hw_mem_hole_info mem_hole;
523 u32 reset_memhole = 1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000524#endif
525
Marc Jones8d595692012-03-15 12:55:26 -0600526 pci_tolm = 0xffffffffUL;
527 for (link = dev->link_list; link; link = link->next) {
528 pci_tolm = my_find_pci_tolm(link, pci_tolm);
529 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000530
Marc Jones8d595692012-03-15 12:55:26 -0600531 // FIXME handle interleaved nodes. If you fix this here, please fix
532 // amdk8, too.
533 mmio_basek = pci_tolm >> 10;
534 /* Round mmio_basek to something the processor can support */
535 mmio_basek &= ~((1 << 6) - 1);
Frank Vibrans39fca802011-02-14 18:35:15 +0000536
Marc Jones8d595692012-03-15 12:55:26 -0600537 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
538 // MMIO hole. If you fix this here, please fix amdk8, too.
539 /* Round the mmio hole to 64M */
540 mmio_basek &= ~((64 * 1024) - 1);
Frank Vibrans39fca802011-02-14 18:35:15 +0000541
542#if CONFIG_HW_MEM_HOLE_SIZEK != 0
543/* if the hw mem hole is already set in raminit stage, here we will compare
544 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
545 * use hole_basek as mmio_basek and we don't need to reset hole.
546 * otherwise We reset the hole to the mmio_basek
547 */
548
Marc Jones8d595692012-03-15 12:55:26 -0600549 mem_hole = get_hw_mem_hole_info();
Frank Vibrans39fca802011-02-14 18:35:15 +0000550
Marc Jones8d595692012-03-15 12:55:26 -0600551 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
552 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
553 mmio_basek = mem_hole.hole_startk;
554 reset_memhole = 0;
555 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000556#endif
557
Marc Jones8d595692012-03-15 12:55:26 -0600558 idx = 0x10;
Frank Vibrans39fca802011-02-14 18:35:15 +0000559
Marc Jones8d595692012-03-15 12:55:26 -0600560 struct dram_base_mask_t d;
561 resource_t basek, limitk, sizek; // 4 1T
Frank Vibrans39fca802011-02-14 18:35:15 +0000562
Marc Jones8d595692012-03-15 12:55:26 -0600563 d = get_dram_base_mask(0);
Frank Vibrans39fca802011-02-14 18:35:15 +0000564
Marc Jones8d595692012-03-15 12:55:26 -0600565 if (d.mask & 1) {
566 basek = ((resource_t) ((u64) d.base)) << 8;
567 limitk = (resource_t) (((u64) d.mask << 8) | 0xFFFFFF);
568 printk(BIOS_DEBUG,
569 "adsr: (before) basek = %llx, limitk = %llx.\n", basek,
570 limitk);
Frank Vibrans39fca802011-02-14 18:35:15 +0000571
Marc Jones8d595692012-03-15 12:55:26 -0600572 /* Convert these values to multiples of 1K for ease of math. */
573 basek >>= 10;
574 limitk >>= 10;
575 sizek = limitk - basek + 1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000576
Marc Jones8d595692012-03-15 12:55:26 -0600577 printk(BIOS_DEBUG,
578 "adsr: (after) basek = %llx, limitk = %llx, sizek = %llx.\n",
579 basek, limitk, sizek);
Frank Vibrans39fca802011-02-14 18:35:15 +0000580
Marc Jones8d595692012-03-15 12:55:26 -0600581 /* see if we need a hole from 0xa0000 to 0xbffff */
582 if ((basek < 640) && (sizek > 768)) {
583 printk(BIOS_DEBUG,"adsr - 0xa0000 to 0xbffff resource.\n");
584 ram_resource(dev, (idx | 0), basek, 640 - basek);
585 idx += 0x10;
586 basek = 768;
587 sizek = limitk - 768;
588 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000589
Marc Jones8d595692012-03-15 12:55:26 -0600590 printk(BIOS_DEBUG,
591 "adsr: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
592 mmio_basek, basek, limitk);
Frank Vibrans39fca802011-02-14 18:35:15 +0000593
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300594 /* split the region to accommodate pci memory space */
Marc Jones8d595692012-03-15 12:55:26 -0600595 if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) {
596 if (basek <= mmio_basek) {
Subrata Banikb1434fc2019-03-15 22:20:41 +0530597 unsigned int pre_sizek;
Marc Jones8d595692012-03-15 12:55:26 -0600598 pre_sizek = mmio_basek - basek;
599 if (pre_sizek > 0) {
600 ram_resource(dev, idx, basek,
601 pre_sizek);
602 idx += 0x10;
603 sizek -= pre_sizek;
Marc Jones8d595692012-03-15 12:55:26 -0600604 }
Marc Jones8d595692012-03-15 12:55:26 -0600605 basek = mmio_basek;
606 }
607 if ((basek + sizek) <= 4 * 1024 * 1024) {
608 sizek = 0;
609 } else {
610 basek = 4 * 1024 * 1024;
611 sizek -= (4 * 1024 * 1024 - mmio_basek);
612 }
613 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000614
Marc Jones8d595692012-03-15 12:55:26 -0600615 ram_resource(dev, (idx | 0), basek, sizek);
616 idx += 0x10;
Marc Jones8d595692012-03-15 12:55:26 -0600617 printk(BIOS_DEBUG,
618 "%d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", 0,
619 mmio_basek, basek, limitk);
Marc Jones8d595692012-03-15 12:55:26 -0600620 }
621 printk(BIOS_DEBUG, " adsr - mmio_basek = %lx.\n", mmio_basek);
Frank Vibrans39fca802011-02-14 18:35:15 +0000622
Kyösti Mälkki61be3602017-04-15 20:07:53 +0300623 add_uma_resource_below_tolm(dev, 7);
Frank Vibrans39fca802011-02-14 18:35:15 +0000624
Marc Jones8d595692012-03-15 12:55:26 -0600625 for (link = dev->link_list; link; link = link->next) {
626 if (link->children) {
627 assign_resources(link);
628 }
629 }
630 printk(BIOS_DEBUG, " adsr - leaving this lovely routine.\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000631}
632
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600633static const char *domain_acpi_name(const struct device *dev)
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100634{
635 if (dev->path.type == DEVICE_PATH_DOMAIN)
636 return "PCI0";
637
638 return NULL;
639}
640
Frank Vibrans39fca802011-02-14 18:35:15 +0000641/* Bus related code */
642
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200643static void cpu_bus_scan(struct device *dev)
zbaof7223732012-04-13 13:42:15 +0800644{
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300645 struct bus *cpu_bus = dev->link_list;
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200646 struct device *cpu;
zbaof7223732012-04-13 13:42:15 +0800647 int apic_id, cores_found;
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000648
zbaof7223732012-04-13 13:42:15 +0800649 /* There is only one node for fam14, but there may be multiple cores. */
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300650 cpu = pcidev_on_root(0x18, 0);
zbaof7223732012-04-13 13:42:15 +0800651 if (!cpu)
652 printk(BIOS_ERR, "ERROR: %02x:%02x.0 not found", 0, 0x18);
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000653
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +0300654 cores_found = (pci_read_config32(pcidev_on_root(0x18, 0x3),
655 0xe8) >> 12) & 3;
zbaof7223732012-04-13 13:42:15 +0800656 printk(BIOS_DEBUG, " AP siblings=%d\n", cores_found);
657
zbaof7223732012-04-13 13:42:15 +0800658 for (apic_id = 0; apic_id <= cores_found; apic_id++) {
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300659 cpu = add_cpu_device(cpu_bus, apic_id, 1);
660 if (cpu)
661 amd_cpu_topology(cpu, 0, apic_id);
Marc Jones8d595692012-03-15 12:55:26 -0600662 }
zbaof7223732012-04-13 13:42:15 +0800663}
664
Elyes HAOUAS0d7c7a82018-05-09 17:58:33 +0200665static void cpu_bus_init(struct device *dev)
zbaof7223732012-04-13 13:42:15 +0800666{
667 initialize_cpus(dev->link_list);
Frank Vibrans39fca802011-02-14 18:35:15 +0000668}
669
Frank Vibrans39fca802011-02-14 18:35:15 +0000670/* North Bridge Structures */
671
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300672static void northbridge_fill_ssdt_generator(struct device *device)
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200673{
674 msr_t msr;
675 char pscope[] = "\\_SB.PCI0";
676
677 acpigen_write_scope(pscope);
678 msr = rdmsr(TOP_MEM);
679 acpigen_write_name_dword("TOM1", msr.lo);
680 msr = rdmsr(TOP_MEM2);
681 /*
682 * Since XP only implements parts of ACPI 2.0, we can't use a qword
683 * here.
684 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
685 * slide 22ff.
686 * Shift value right by 20 bit to make it fit into 32bit,
687 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
688 */
689 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
690 acpigen_pop_len();
691}
692
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100693static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200694{
695 void *addr, *current;
696
697 /* Skip the HEST header. */
698 current = (void *)(hest + 1);
699
700 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
701 if (addr != NULL)
Stefan Reinauer29e65482015-06-18 01:18:09 -0700702 current += acpi_create_hest_error_source(hest, current, 0,
703 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200704
705 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
706 if (addr != NULL)
Stefan Reinauer29e65482015-06-18 01:18:09 -0700707 current += acpi_create_hest_error_source(hest, current, 1,
708 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200709
710 return (unsigned long)current;
711}
712
Michał Żygowski9550e972020-03-20 13:56:46 +0100713static void patch_ssdt_processor_scope(acpi_header_t *ssdt)
714{
715 unsigned int len = ssdt->length - sizeof(acpi_header_t);
716 unsigned int i;
717
718 for (i = sizeof(acpi_header_t); i < len; i++) {
719 /* Search for _PR_ scope and replace it with _SB_ */
720 if (*(uint32_t *)((unsigned long)ssdt + i) == 0x5f52505f)
721 *(uint32_t *)((unsigned long)ssdt + i) = 0x5f42535f;
722 }
723 /* Recalculate checksum */
724 ssdt->checksum = 0;
725 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
726}
727
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +0300728static unsigned long agesa_write_acpi_tables(struct device *device,
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200729 unsigned long current,
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200730 acpi_rsdp_t *rsdp)
731{
732 acpi_srat_t *srat;
733 acpi_slit_t *slit;
734 acpi_header_t *ssdt;
735 acpi_header_t *alib;
736 acpi_hest_t *hest;
737
738 /* HEST */
739 current = ALIGN(current, 8);
740 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100741 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200742 acpi_add_table(rsdp, (void *)current);
743 current += ((acpi_header_t *)current)->length;
744
745 /* SRAT */
746 current = ALIGN(current, 8);
747 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
748 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
749 if (srat != NULL) {
750 memcpy((void *)current, srat, srat->header.length);
751 srat = (acpi_srat_t *) current;
752 current += srat->header.length;
753 acpi_add_table(rsdp, srat);
754 }
755 else {
756 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
757 }
758
759 /* SLIT */
760 current = ALIGN(current, 8);
761 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
762 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
763 if (slit != NULL) {
764 memcpy((void *)current, slit, slit->header.length);
765 slit = (acpi_slit_t *) current;
766 current += slit->header.length;
767 acpi_add_table(rsdp, slit);
768 }
769 else {
770 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
771 }
772
773 /* SSDT */
774 current = ALIGN(current, 16);
775 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
776 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
777 if (alib != NULL) {
778 memcpy((void *)current, alib, alib->length);
779 alib = (acpi_header_t *) current;
780 current += alib->length;
781 acpi_add_table(rsdp, (void *)alib);
782 } else {
783 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
784 }
785
786 /* The DSDT needs additional work for the AGESA SSDT Pstate table */
787 /* Keep the comment for a while. */
788 current = ALIGN(current, 16);
789 printk(BIOS_DEBUG, "ACPI: * AGESA SSDT Pstate at %lx\n", current);
790 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
791 if (ssdt != NULL) {
Michał Żygowski9550e972020-03-20 13:56:46 +0100792 hexdump(ssdt, ssdt->length);
793 patch_ssdt_processor_scope(ssdt);
794 hexdump(ssdt, ssdt->length);
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200795 memcpy((void *)current, ssdt, ssdt->length);
796 ssdt = (acpi_header_t *) current;
797 current += ssdt->length;
798 acpi_add_table(rsdp,ssdt);
799 } else {
800 printk(BIOS_DEBUG, " AGESA SSDT Pstate table NULL. Skipping.\n");
801 }
802
803 return current;
804}
805
Frank Vibrans39fca802011-02-14 18:35:15 +0000806static struct device_operations northbridge_operations = {
Marc Jones8a49ac72013-01-16 17:02:20 -0700807 .read_resources = nb_read_resources,
808 .set_resources = nb_set_resources,
Marc Jones8d595692012-03-15 12:55:26 -0600809 .enable_resources = pci_dev_enable_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200810 .acpi_fill_ssdt = northbridge_fill_ssdt_generator,
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200811 .write_acpi_tables = agesa_write_acpi_tables,
Marc Jones8d595692012-03-15 12:55:26 -0600812 .init = northbridge_init,
813 .enable = 0,.ops_pci = 0,
Frank Vibrans39fca802011-02-14 18:35:15 +0000814};
815
Frank Vibrans39fca802011-02-14 18:35:15 +0000816static const struct pci_driver northbridge_driver __pci_driver = {
Marc Jones8d595692012-03-15 12:55:26 -0600817 .ops = &northbridge_operations,
818 .vendor = PCI_VENDOR_ID_AMD,
819 .device = 0x1510,
Frank Vibrans39fca802011-02-14 18:35:15 +0000820};
821
efdesign9805a89ab2011-06-20 17:38:49 -0700822struct chip_operations northbridge_amd_agesa_family14_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600823 CHIP_NAME("AMD Family 14h Northbridge")
824 .enable_dev = 0,
Frank Vibrans39fca802011-02-14 18:35:15 +0000825};
826
Frank Vibrans39fca802011-02-14 18:35:15 +0000827/* Root Complex Structures */
828
Frank Vibrans39fca802011-02-14 18:35:15 +0000829static struct device_operations pci_domain_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600830 .read_resources = domain_read_resources,
831 .set_resources = domain_set_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100832 .init = DEVICE_NOOP,
Marc Jones8d595692012-03-15 12:55:26 -0600833 .scan_bus = pci_domain_scan_bus,
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100834 .acpi_name = domain_acpi_name,
Frank Vibrans39fca802011-02-14 18:35:15 +0000835};
836
Frank Vibrans39fca802011-02-14 18:35:15 +0000837static struct device_operations cpu_bus_ops = {
Edward O'Callaghan2837ab22014-11-06 08:57:40 +1100838 .read_resources = DEVICE_NOOP,
839 .set_resources = DEVICE_NOOP,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100840 .enable_resources = DEVICE_NOOP,
Marc Jones8d595692012-03-15 12:55:26 -0600841 .init = cpu_bus_init,
zbaof7223732012-04-13 13:42:15 +0800842 .scan_bus = cpu_bus_scan,
Frank Vibrans39fca802011-02-14 18:35:15 +0000843};
844
Kyösti Mälkki87213b62012-08-27 20:00:33 +0300845static void root_complex_enable_dev(struct device *dev)
846{
847 static int done = 0;
848
Kyösti Mälkki87213b62012-08-27 20:00:33 +0300849 if (!done) {
850 setup_bsp_ramtop();
Kyösti Mälkki87213b62012-08-27 20:00:33 +0300851 done = 1;
852 }
853
Marc Jones8d595692012-03-15 12:55:26 -0600854 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800855 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Marc Jones8d595692012-03-15 12:55:26 -0600856 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800857 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Marc Jones8d595692012-03-15 12:55:26 -0600858 dev->ops = &cpu_bus_ops;
859 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000860}
861
efdesign9805a89ab2011-06-20 17:38:49 -0700862struct chip_operations northbridge_amd_agesa_family14_root_complex_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600863 CHIP_NAME("AMD Family 14h Root Complex")
864 .enable_dev = root_complex_enable_dev,
Frank Vibrans39fca802011-02-14 18:35:15 +0000865};
Kyösti Mälkki2b218e32019-01-15 11:14:28 +0200866
867/********************************************************************
868* Change the vendor / device IDs to match the generic VBIOS header.
869********************************************************************/
870u32 map_oprom_vendev(u32 vendev)
871{
872 u32 new_vendev = vendev;
873
874 switch (vendev) {
875 case 0x10029809:
876 case 0x10029808:
877 case 0x10029807:
878 case 0x10029806:
879 case 0x10029805:
880 case 0x10029804:
881 case 0x10029803:
882 new_vendev = 0x10029802;
883 break;
884 }
885
886 return new_vendev;
887}