blob: 7cc812bf5970b81e401313bcbf4a664e066841d4 [file] [log] [blame]
Frank Vibrans39fca802011-02-14 18:35:15 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Frank Vibrans39fca802011-02-14 18:35:15 +000018 */
19
20#include <console/console.h>
21#include <arch/io.h>
22#include <stdint.h>
23#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
26#include <device/hypertransport.h>
27#include <stdlib.h>
28#include <string.h>
Ronald G. Minnich5079a0d2012-11-27 11:32:38 -080029#include <lib.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000030#include <cpu/cpu.h>
Marc Jones5750ed22012-03-15 13:21:41 -060031#include <cbmem.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000032
33#include <cpu/x86/lapic.h>
Kyösti Mälkki55fff9302012-07-11 08:02:39 +030034#include <cpu/amd/mtrr.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000035
efdesign983f5ebd62011-09-14 13:47:17 -060036#include "agesawrapper.h"
Frank Vibrans39fca802011-02-14 18:35:15 +000037#include "northbridge.h"
Kerry Shefeed3292011-08-18 18:03:44 +080038#if CONFIG_AMD_SB_CIMX
39#include <sb_cimx.h>
40#endif
Frank Vibrans39fca802011-02-14 18:35:15 +000041
Frank Vibrans39fca802011-02-14 18:35:15 +000042//#define FX_DEVS NODE_NUMS
43#define FX_DEVS 1
44
45static device_t __f0_dev[FX_DEVS];
46static device_t __f1_dev[FX_DEVS];
47static device_t __f2_dev[FX_DEVS];
48static device_t __f4_dev[FX_DEVS];
Marc Jones8d595692012-03-15 12:55:26 -060049static unsigned fx_devs = 0;
Frank Vibrans39fca802011-02-14 18:35:15 +000050
51device_t get_node_pci(u32 nodeid, u32 fn)
52{
zbao49bb26a42012-08-03 15:44:42 +080053 if ((CONFIG_CDB + nodeid) < 32) {
54 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
55 } else {
56 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
57 }
Frank Vibrans39fca802011-02-14 18:35:15 +000058}
59
Frank Vibrans39fca802011-02-14 18:35:15 +000060static void get_fx_devs(void)
61{
Marc Jones8d595692012-03-15 12:55:26 -060062 int i;
63 for (i = 0; i < FX_DEVS; i++) {
64 __f0_dev[i] = get_node_pci(i, 0);
65 __f1_dev[i] = get_node_pci(i, 1);
66 __f2_dev[i] = get_node_pci(i, 2);
67 __f4_dev[i] = get_node_pci(i, 4);
68 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
69 fx_devs = i + 1;
70 }
71 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
72 die("Cannot find 0:0x18.[0|1]\n");
73 }
Frank Vibrans39fca802011-02-14 18:35:15 +000074}
75
Frank Vibrans39fca802011-02-14 18:35:15 +000076static u32 f1_read_config32(unsigned reg)
77{
Marc Jones8d595692012-03-15 12:55:26 -060078 if (fx_devs == 0)
79 get_fx_devs();
80 return pci_read_config32(__f1_dev[0], reg);
Frank Vibrans39fca802011-02-14 18:35:15 +000081}
82
Frank Vibrans39fca802011-02-14 18:35:15 +000083static void f1_write_config32(unsigned reg, u32 value)
84{
Marc Jones8d595692012-03-15 12:55:26 -060085 int i;
86 if (fx_devs == 0)
87 get_fx_devs();
88 for (i = 0; i < fx_devs; i++) {
89 device_t dev;
90 dev = __f1_dev[i];
91 if (dev && dev->enabled) {
92 pci_write_config32(dev, reg, value);
93 }
94 }
Frank Vibrans39fca802011-02-14 18:35:15 +000095}
96
Frank Vibrans39fca802011-02-14 18:35:15 +000097static u32 amdfam14_nodeid(device_t dev)
98{
Marc Jones8d595692012-03-15 12:55:26 -060099 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
Frank Vibrans39fca802011-02-14 18:35:15 +0000100}
101
Frank Vibrans39fca802011-02-14 18:35:15 +0000102#include "amdfam14_conf.c"
103
Frank Vibrans39fca802011-02-14 18:35:15 +0000104static void northbridge_init(device_t dev)
105{
Marc Jones8d595692012-03-15 12:55:26 -0600106 printk(BIOS_DEBUG, "Northbridge init\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000107}
108
Frank Vibrans39fca802011-02-14 18:35:15 +0000109static void set_vga_enable_reg(u32 nodeid, u32 linkn)
110{
Marc Jones8d595692012-03-15 12:55:26 -0600111 u32 val;
Frank Vibrans39fca802011-02-14 18:35:15 +0000112
Marc Jones8d595692012-03-15 12:55:26 -0600113 val = 1 | (nodeid << 4) | (linkn << 12);
114 /* it will routing (1)mmio 0xa0000:0xbffff (2) io 0x3b0:0x3bb,
115 0x3c0:0x3df */
116 f1_write_config32(0xf4, val);
Frank Vibrans39fca802011-02-14 18:35:15 +0000117
118}
119
Frank Vibrans39fca802011-02-14 18:35:15 +0000120static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
Marc Jones8d595692012-03-15 12:55:26 -0600121 unsigned goal_link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000122{
Marc Jones8d595692012-03-15 12:55:26 -0600123 struct resource *res;
124 unsigned nodeid, link = 0;
125 int result;
126 res = 0;
127 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
128 device_t dev;
129 dev = __f0_dev[nodeid];
130 if (!dev)
131 continue;
132 for (link = 0; !res && (link < 8); link++) {
133 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
134 }
135 }
136 result = 2;
137 if (res) {
138 result = 0;
139 if ((goal_link == (link - 1)) &&
140 (goal_nodeid == (nodeid - 1)) && (res->flags <= 1)) {
141 result = 1;
142 }
143 }
144 return result;
Frank Vibrans39fca802011-02-14 18:35:15 +0000145}
146
Marc Jones8d595692012-03-15 12:55:26 -0600147static struct resource *amdfam14_find_iopair(device_t dev, unsigned nodeid,
148 unsigned link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000149{
Marc Jones8d595692012-03-15 12:55:26 -0600150 struct resource *resource;
151 u32 result, reg;
152 resource = 0;
153 reg = 0;
154 result = reg_useable(0xc0, dev, nodeid, link);
155 if (result >= 1) {
156 /* I have been allocated this one */
157 reg = 0xc0;
158 }
159 /* Ext conf space */
160 if (!reg) {
161 /* Because of Extend conf space, we will never run out of reg,
162 * but we need one index to differ them. So ,same node and same
163 * link can have multi range
164 */
165 u32 index = get_io_addr_index(nodeid, link);
166 reg = 0x110 + (index << 24) + (4 << 20); // index could be 0, 255
167 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000168
Marc Jones8d595692012-03-15 12:55:26 -0600169 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
Frank Vibrans39fca802011-02-14 18:35:15 +0000170
Marc Jones8d595692012-03-15 12:55:26 -0600171 return resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000172}
173
Marc Jones8d595692012-03-15 12:55:26 -0600174static struct resource *amdfam14_find_mempair(device_t dev, u32 nodeid,
175 u32 link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000176{
Marc Jones8d595692012-03-15 12:55:26 -0600177 struct resource *resource;
178 u32 free_reg, reg;
179 resource = 0;
180 free_reg = 0;
181 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
182 int result;
183 result = reg_useable(reg, dev, nodeid, link);
184 if (result == 1) {
185 /* I have been allocated this one */
186 break;
187 } else if (result > 1) {
188 /* I have a free register pair */
189 free_reg = reg;
190 }
191 }
192 if (reg > 0xb8) {
193 reg = free_reg;
194 }
195 /* Ext conf space */
196 if (!reg) {
197 /* Because of Extend conf space, we will never run out of reg,
198 * but we need one index to differ them. So ,same node and same
199 * link can have multi range
200 */
201 u32 index = get_mmio_addr_index(nodeid, link);
202 reg = 0x110 + (index << 24) + (6 << 20); // index could be 0, 63
Frank Vibrans39fca802011-02-14 18:35:15 +0000203
Marc Jones8d595692012-03-15 12:55:26 -0600204 }
205 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
206 return resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000207}
208
Frank Vibrans39fca802011-02-14 18:35:15 +0000209static void amdfam14_link_read_bases(device_t dev, u32 nodeid, u32 link)
210{
Marc Jones8d595692012-03-15 12:55:26 -0600211 struct resource *resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000212
Marc Jones8d595692012-03-15 12:55:26 -0600213 /* Initialize the io space constraints on the current bus */
214 resource = amdfam14_find_iopair(dev, nodeid, link);
215 if (resource) {
216 u32 align;
Patrick Georgie1667822012-05-05 15:29:32 +0200217#if CONFIG_EXT_CONF_SUPPORT
Marc Jones8d595692012-03-15 12:55:26 -0600218 if ((resource->index & 0x1fff) == 0x1110) { // ext
219 align = 8;
220 } else
Frank Vibrans39fca802011-02-14 18:35:15 +0000221#endif
Marc Jones8d595692012-03-15 12:55:26 -0600222 align = log2(HT_IO_HOST_ALIGN);
223 resource->base = 0;
224 resource->size = 0;
225 resource->align = align;
226 resource->gran = align;
227 resource->limit = 0xffffUL;
228 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
229 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000230
Marc Jones8d595692012-03-15 12:55:26 -0600231 /* Initialize the prefetchable memory constraints on the current bus */
232 resource = amdfam14_find_mempair(dev, nodeid, link);
233 if (resource) {
234 resource->base = 0;
235 resource->size = 0;
236 resource->align = log2(HT_MEM_HOST_ALIGN);
237 resource->gran = log2(HT_MEM_HOST_ALIGN);
238 resource->limit = 0xffffffffffULL;
239 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
240 resource->flags |= IORESOURCE_BRIDGE;
Frank Vibrans39fca802011-02-14 18:35:15 +0000241
Patrick Georgie1667822012-05-05 15:29:32 +0200242#if CONFIG_EXT_CONF_SUPPORT
Marc Jones8d595692012-03-15 12:55:26 -0600243 if ((resource->index & 0x1fff) == 0x1110) { // ext
244 normalize_resource(resource);
245 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000246#endif
247
Marc Jones8d595692012-03-15 12:55:26 -0600248 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000249
Marc Jones8d595692012-03-15 12:55:26 -0600250 /* Initialize the memory constraints on the current bus */
251 resource = amdfam14_find_mempair(dev, nodeid, link);
252 if (resource) {
253 resource->base = 0;
254 resource->size = 0;
255 resource->align = log2(HT_MEM_HOST_ALIGN);
256 resource->gran = log2(HT_MEM_HOST_ALIGN);
257 resource->limit = 0xffffffffffULL;
258 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
Patrick Georgie1667822012-05-05 15:29:32 +0200259#if CONFIG_EXT_CONF_SUPPORT
Marc Jones8d595692012-03-15 12:55:26 -0600260 if ((resource->index & 0x1fff) == 0x1110) { // ext
261 normalize_resource(resource);
262 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000263#endif
Marc Jones8d595692012-03-15 12:55:26 -0600264 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000265}
266
267static u32 my_find_pci_tolm(struct bus *bus, u32 tolm)
268{
Marc Jones8d595692012-03-15 12:55:26 -0600269 struct resource *min;
270 min = 0;
271 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test,
272 &min);
273 if (min && tolm > min->base) {
274 tolm = min->base;
275 }
276 return tolm;
Frank Vibrans39fca802011-02-14 18:35:15 +0000277}
278
279#if CONFIG_HW_MEM_HOLE_SIZEK != 0
280
281struct hw_mem_hole_info {
Marc Jones8d595692012-03-15 12:55:26 -0600282 unsigned hole_startk;
283 int node_id;
Frank Vibrans39fca802011-02-14 18:35:15 +0000284};
285
286static struct hw_mem_hole_info get_hw_mem_hole_info(void)
287{
Marc Jones8d595692012-03-15 12:55:26 -0600288 struct hw_mem_hole_info mem_hole;
Frank Vibrans39fca802011-02-14 18:35:15 +0000289
Marc Jones8d595692012-03-15 12:55:26 -0600290 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
291 mem_hole.node_id = -1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000292
Marc Jones8d595692012-03-15 12:55:26 -0600293 struct dram_base_mask_t d;
294 u32 hole;
295 d = get_dram_base_mask(0);
296 if (d.mask & 1) {
297 hole = pci_read_config32(__f1_dev[0], 0xf0);
298 if (hole & 1) { // we find the hole
299 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
300 mem_hole.node_id = 0; // record the node No with hole
301 }
302 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000303#if 0
Marc Jones8d595692012-03-15 12:55:26 -0600304 /* We need to double check if there is speical set on base reg and limit reg
305 * are not continous instead of hole, it will find out it's hole_startk
306 */
307 if (mem_hole.node_id == -1) {
308 resource_t limitk_pri = 0;
309 struct dram_base_mask_t d;
310 resource_t base_k, limit_k;
311 d = get_dram_base_mask(0);
312 if (d.base & 1) {
313 base_k = ((resource_t) (d.base & 0x1fffff00)) << 9;
314 if (base_k <= 4 * 1024 * 1024) {
315 if (limitk_pri != base_k) { // we find the hole
316 mem_hole.hole_startk = (unsigned)limitk_pri; // must be below 4G
317 mem_hole.node_id = 0;
318 }
319 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000320
Marc Jones8d595692012-03-15 12:55:26 -0600321 limit_k =
322 ((resource_t) ((d.mask + 0x00000100) & 0x1fffff00))
323 << 9;
324 limitk_pri = limit_k;
325 }
326 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000327#endif
efdesign9805a89ab2011-06-20 17:38:49 -0700328
Marc Jones8d595692012-03-15 12:55:26 -0600329 return mem_hole;
Frank Vibrans39fca802011-02-14 18:35:15 +0000330}
331#endif
332
Marc Jones8a49ac72013-01-16 17:02:20 -0700333static void nb_read_resources(device_t dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000334{
Marc Jones8d595692012-03-15 12:55:26 -0600335 u32 nodeid;
336 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000337
Mike Loptien58089e82013-01-29 15:45:09 -0700338 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000339
Marc Jones8d595692012-03-15 12:55:26 -0600340 nodeid = amdfam14_nodeid(dev);
341 for (link = dev->link_list; link; link = link->next) {
342 if (link->children) {
343 amdfam14_link_read_bases(dev, nodeid, link->link_num);
344 }
345 }
Marc Jonesd5c998b2013-01-16 17:14:24 -0700346
347 /*
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800348 * This MMCONF resource must be reserved in the PCI domain.
Marc Jonesd5c998b2013-01-16 17:14:24 -0700349 * It is not honored by the coreboot resource allocator if it is in
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800350 * the CPU_CLUSTER.
Marc Jonesd5c998b2013-01-16 17:14:24 -0700351 */
352#if CONFIG_MMCONF_SUPPORT
353 struct resource *resource = new_resource(dev, 0xc0010058);
354 resource->base = CONFIG_MMCONF_BASE_ADDRESS;
355 resource->size = CONFIG_MMCONF_BUS_NUMBER * 4096 * 256;
356 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
357 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
358#endif
Frank Vibrans39fca802011-02-14 18:35:15 +0000359}
360
Marc Jones8d595692012-03-15 12:55:26 -0600361static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
Frank Vibrans39fca802011-02-14 18:35:15 +0000362{
Marc Jones8d595692012-03-15 12:55:26 -0600363 resource_t rbase, rend;
364 unsigned reg, link_num;
365 char buf[50];
Frank Vibrans39fca802011-02-14 18:35:15 +0000366
Mike Loptien58089e82013-01-29 15:45:09 -0700367 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000368
Marc Jones8d595692012-03-15 12:55:26 -0600369 /* Make certain the resource has actually been set */
370 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
371 return;
372 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000373
Marc Jones8d595692012-03-15 12:55:26 -0600374 /* If I have already stored this resource don't worry about it */
375 if (resource->flags & IORESOURCE_STORED) {
376 return;
377 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000378
Marc Jones8d595692012-03-15 12:55:26 -0600379 /* Only handle PCI memory and IO resources */
380 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
381 return;
Frank Vibrans39fca802011-02-14 18:35:15 +0000382
Marc Jones8d595692012-03-15 12:55:26 -0600383 /* Ensure I am actually looking at a resource of function 1 */
384 if ((resource->index & 0xffff) < 0x1000) {
385 return;
386 }
387 /* Get the base address */
388 rbase = resource->base;
Frank Vibrans39fca802011-02-14 18:35:15 +0000389
Marc Jones8d595692012-03-15 12:55:26 -0600390 /* Get the limit (rounded up) */
391 rend = resource_end(resource);
Frank Vibrans39fca802011-02-14 18:35:15 +0000392
Marc Jones8d595692012-03-15 12:55:26 -0600393 /* Get the register and link */
394 reg = resource->index & 0xfff; // 4k
395 link_num = IOINDEX_LINK(resource->index);
Frank Vibrans39fca802011-02-14 18:35:15 +0000396
Marc Jones8d595692012-03-15 12:55:26 -0600397 if (resource->flags & IORESOURCE_IO) {
398 set_io_addr_reg(dev, nodeid, link_num, reg, rbase >> 8,
399 rend >> 8);
400 } else if (resource->flags & IORESOURCE_MEM) {
401 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >> 24),
402 rbase >> 8, rend >> 8, 1); // [39:8]
403 }
404 resource->flags |= IORESOURCE_STORED;
405 sprintf(buf, " <node %x link %x>", nodeid, link_num);
406 report_resource_stored(dev, resource, buf);
Frank Vibrans39fca802011-02-14 18:35:15 +0000407}
408
efdesign983f5ebd62011-09-14 13:47:17 -0600409#if CONFIG_CONSOLE_VGA_MULTI
Marc Jones8d595692012-03-15 12:55:26 -0600410extern device_t vga_pri; // the primary vga device, defined in device.c
Frank Vibrans39fca802011-02-14 18:35:15 +0000411#endif
412
413static void create_vga_resource(device_t dev, unsigned nodeid)
414{
Marc Jones8d595692012-03-15 12:55:26 -0600415 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000416
Mike Loptien58089e82013-01-29 15:45:09 -0700417 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000418
Marc Jones8d595692012-03-15 12:55:26 -0600419 /* find out which link the VGA card is connected,
420 * we only deal with the 'first' vga card */
421 for (link = dev->link_list; link; link = link->next) {
422 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
efdesign983f5ebd62011-09-14 13:47:17 -0600423#if CONFIG_CONSOLE_VGA_MULTI
Marc Jones8d595692012-03-15 12:55:26 -0600424 printk(BIOS_DEBUG,
425 "VGA: vga_pri bus num = %d bus range [%d,%d]\n",
426 vga_pri->bus->secondary, link->secondary,
427 link->subordinate);
428 /* We need to make sure the vga_pri is under the link */
429 if ((vga_pri->bus->secondary >= link->secondary) &&
430 (vga_pri->bus->secondary <= link->subordinate))
Frank Vibrans39fca802011-02-14 18:35:15 +0000431#endif
Marc Jones8d595692012-03-15 12:55:26 -0600432 break;
433 }
434 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000435
Marc Jones8d595692012-03-15 12:55:26 -0600436 /* no VGA card installed */
437 if (link == NULL)
438 return;
Frank Vibrans39fca802011-02-14 18:35:15 +0000439
Marc Jones8d595692012-03-15 12:55:26 -0600440 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n",
441 dev_path(dev), nodeid, link->link_num);
442 set_vga_enable_reg(nodeid, link->link_num);
Frank Vibrans39fca802011-02-14 18:35:15 +0000443}
444
Marc Jones8a49ac72013-01-16 17:02:20 -0700445static void nb_set_resources(device_t dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000446{
Marc Jones8d595692012-03-15 12:55:26 -0600447 unsigned nodeid;
448 struct bus *bus;
449 struct resource *res;
Frank Vibrans39fca802011-02-14 18:35:15 +0000450
Mike Loptien58089e82013-01-29 15:45:09 -0700451 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
efdesign9805a89ab2011-06-20 17:38:49 -0700452
Marc Jones8d595692012-03-15 12:55:26 -0600453 /* Find the nodeid */
454 nodeid = amdfam14_nodeid(dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000455
Marc Jones8d595692012-03-15 12:55:26 -0600456 create_vga_resource(dev, nodeid);
Frank Vibrans39fca802011-02-14 18:35:15 +0000457
Marc Jones8d595692012-03-15 12:55:26 -0600458 /* Set each resource we have found */
459 for (res = dev->resource_list; res; res = res->next) {
460 set_resource(dev, res, nodeid);
461 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000462
Marc Jones8d595692012-03-15 12:55:26 -0600463 for (bus = dev->link_list; bus; bus = bus->next) {
464 if (bus->children) {
465 assign_resources(bus);
466 }
467 }
Marc Jonesd5c998b2013-01-16 17:14:24 -0700468
469 /* Print the MMCONF region if it has been reserved. */
470 res = find_resource(dev, 0xc0010058);
471 if (res) {
472 report_resource_stored(dev, res, " <mmconfig>");
473 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000474}
475
Frank Vibrans39fca802011-02-14 18:35:15 +0000476/* Domain/Root Complex related code */
477
478static void domain_read_resources(device_t dev)
479{
Marc Jones8d595692012-03-15 12:55:26 -0600480 unsigned reg;
Frank Vibrans39fca802011-02-14 18:35:15 +0000481
Mike Loptien58089e82013-01-29 15:45:09 -0700482 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000483
Marc Jones8d595692012-03-15 12:55:26 -0600484 /* Find the already assigned resource pairs */
485 get_fx_devs();
486 for (reg = 0x80; reg <= 0xc0; reg += 0x08) {
487 u32 base, limit;
488 base = f1_read_config32(reg);
489 limit = f1_read_config32(reg + 0x04);
490 /* Is this register allocated? */
491 if ((base & 3) != 0) {
492 unsigned nodeid, reg_link;
493 device_t reg_dev;
494 if (reg < 0xc0) { // mmio
495 nodeid = (limit & 0xf) + (base & 0x30);
496 } else { // io
497 nodeid = (limit & 0xf) + ((base >> 4) & 0x30);
498 }
499 reg_link = (limit >> 4) & 7;
500 reg_dev = __f0_dev[nodeid];
501 if (reg_dev) {
502 /* Reserve the resource */
503 struct resource *res;
504 res =
505 new_resource(reg_dev,
506 IOINDEX(0x1000 + reg,
507 reg_link));
508 if (res) {
509 res->flags = 1;
510 }
511 }
512 }
513 }
514 /* FIXME: do we need to check extend conf space?
515 I don't believe that much preset value */
Frank Vibrans39fca802011-02-14 18:35:15 +0000516
Patrick Georgie1667822012-05-05 15:29:32 +0200517#if !CONFIG_PCI_64BIT_PREF_MEM
Marc Jones8d595692012-03-15 12:55:26 -0600518 pci_domain_read_resources(dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000519#else
Marc Jones8d595692012-03-15 12:55:26 -0600520 struct bus *link;
521 struct resource *resource;
522 for (link = dev->link_list; link; link = link->next) {
523 /* Initialize the system wide io space constraints */
524 resource = new_resource(dev, 0 | (link->link_num << 2));
525 resource->base = 0x400;
526 resource->limit = 0xffffUL;
527 resource->flags = IORESOURCE_IO;
Frank Vibrans39fca802011-02-14 18:35:15 +0000528
Marc Jones8d595692012-03-15 12:55:26 -0600529 /* Initialize the system wide prefetchable memory resources constraints */
530 resource = new_resource(dev, 1 | (link->link_num << 2));
531 resource->limit = 0xfcffffffffULL;
532 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
Frank Vibrans39fca802011-02-14 18:35:15 +0000533
Marc Jones8d595692012-03-15 12:55:26 -0600534 /* Initialize the system wide memory resources constraints */
535 resource = new_resource(dev, 2 | (link->link_num << 2));
536 resource->limit = 0xfcffffffffULL;
537 resource->flags = IORESOURCE_MEM;
538 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000539#endif
540}
541
Kyösti Mälkki6b5eb1c2012-07-19 19:26:43 +0300542static void setup_uma_memory(void)
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300543{
544#if CONFIG_GFXUMA
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300545 uint32_t topmem = (uint32_t) bsp_topmem();
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300546 uint32_t sys_mem;
547
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300548 /* refer to UMA Size Consideration in Family14h BKDG. */
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300549 sys_mem = topmem + 0x1000000; // Ignore 16MB allocated for C6 when finding UMA size, refer MemNGetUmaSizeON()
550 if ((bsp_topmem2()>>32) || (sys_mem >= 0x80000000)) {
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300551 uma_memory_size = 0x18000000; /* >= 2G memory, 384M recommended UMA */
552 }
553 else {
554 if (sys_mem >= 0x40000000) {
555 uma_memory_size = 0x10000000; /* >= 1G memory, 256M recommended UMA */
556 } else {
557 uma_memory_size = 0x4000000; /* <1G memory, 64M recommended UMA */
558 }
559 }
560
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300561 uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300562 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
563 __func__, uma_memory_size, uma_memory_base);
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300564#endif
565}
566
Frank Vibrans39fca802011-02-14 18:35:15 +0000567static void domain_set_resources(device_t dev)
568{
Mike Loptien58089e82013-01-29 15:45:09 -0700569 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Marc Jones8d595692012-03-15 12:55:26 -0600570 printk(BIOS_DEBUG, " amsr - incoming dev = %08x\n", (u32) dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000571
Patrick Georgie1667822012-05-05 15:29:32 +0200572#if CONFIG_PCI_64BIT_PREF_MEM
Marc Jones8d595692012-03-15 12:55:26 -0600573 struct resource *io, *mem1, *mem2;
574 struct resource *res;
Frank Vibrans39fca802011-02-14 18:35:15 +0000575#endif
Marc Jones8d595692012-03-15 12:55:26 -0600576 unsigned long mmio_basek;
577 u32 pci_tolm;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300578 u64 ramtop = 0;
Marc Jones8d595692012-03-15 12:55:26 -0600579 int idx;
580 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000581#if CONFIG_HW_MEM_HOLE_SIZEK != 0
Marc Jones8d595692012-03-15 12:55:26 -0600582 struct hw_mem_hole_info mem_hole;
583 u32 reset_memhole = 1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000584#endif
585
Patrick Georgie1667822012-05-05 15:29:32 +0200586#if CONFIG_PCI_64BIT_PREF_MEM
Frank Vibrans39fca802011-02-14 18:35:15 +0000587
Marc Jones8d595692012-03-15 12:55:26 -0600588 printk(BIOS_DEBUG, "adsr - CONFIG_PCI_64BIT_PREF_MEM is true.\n");
589 for (link = dev->link_list; link; link = link->next) {
590 /* Now reallocate the pci resources memory with the
591 * highest addresses I can manage.
592 */
593 mem1 = find_resource(dev, 1 | (link->link_num << 2));
594 mem2 = find_resource(dev, 2 | (link->link_num << 2));
Frank Vibrans39fca802011-02-14 18:35:15 +0000595
Marc Jones8d595692012-03-15 12:55:26 -0600596 printk(BIOS_DEBUG,
597 "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
598 (u32) (mem1->base), (u32) (mem1->limit),
599 (u32) (mem1->size), u32) (mem1->align));
600 printk(BIOS_DEBUG,
601 "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
602 (u32) (mem2->base), (u32) (mem2->limit),
603 (u32) (mem2->size), (u32) (mem2->align));
Frank Vibrans39fca802011-02-14 18:35:15 +0000604
Marc Jones8d595692012-03-15 12:55:26 -0600605 /* See if both resources have roughly the same limits */
606 if (((mem1->limit <= 0xffffffff) && (mem2->limit <= 0xffffffff))
607 || ((mem1->limit > 0xffffffff)
608 && (mem2->limit > 0xffffffff))) {
609 /* If so place the one with the most stringent alignment first
610 */
611 if (mem2->align > mem1->align) {
612 struct resource *tmp;
613 tmp = mem1;
614 mem1 = mem2;
615 mem2 = tmp;
616 }
617 /* Now place the memory as high up as it will go */
618 mem2->base = resource_max(mem2);
619 mem1->limit = mem2->base - 1;
620 mem1->base = resource_max(mem1);
621 } else {
622 /* Place the resources as high up as they will go */
623 mem2->base = resource_max(mem2);
624 mem1->base = resource_max(mem1);
625 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000626
Marc Jones8d595692012-03-15 12:55:26 -0600627 printk(BIOS_DEBUG,
628 "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
629 mem1->base, mem1->limit, mem1->size, mem1->align);
630 printk(BIOS_DEBUG,
631 "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
632 mem2->base, mem2->limit, mem2->size, mem2->align);
633 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000634
Marc Jones8d595692012-03-15 12:55:26 -0600635 for (res = &dev->resource_list; res; res = res->next) {
636 res->flags |= IORESOURCE_ASSIGNED;
637 res->flags |= IORESOURCE_STORED;
638 report_resource_stored(dev, res, "");
639 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000640#endif
641
Marc Jones8d595692012-03-15 12:55:26 -0600642 pci_tolm = 0xffffffffUL;
643 for (link = dev->link_list; link; link = link->next) {
644 pci_tolm = my_find_pci_tolm(link, pci_tolm);
645 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000646
Marc Jones8d595692012-03-15 12:55:26 -0600647 // FIXME handle interleaved nodes. If you fix this here, please fix
648 // amdk8, too.
649 mmio_basek = pci_tolm >> 10;
650 /* Round mmio_basek to something the processor can support */
651 mmio_basek &= ~((1 << 6) - 1);
Frank Vibrans39fca802011-02-14 18:35:15 +0000652
Marc Jones8d595692012-03-15 12:55:26 -0600653 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
654 // MMIO hole. If you fix this here, please fix amdk8, too.
655 /* Round the mmio hole to 64M */
656 mmio_basek &= ~((64 * 1024) - 1);
Frank Vibrans39fca802011-02-14 18:35:15 +0000657
658#if CONFIG_HW_MEM_HOLE_SIZEK != 0
659/* if the hw mem hole is already set in raminit stage, here we will compare
660 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
661 * use hole_basek as mmio_basek and we don't need to reset hole.
662 * otherwise We reset the hole to the mmio_basek
663 */
664
Marc Jones8d595692012-03-15 12:55:26 -0600665 mem_hole = get_hw_mem_hole_info();
Frank Vibrans39fca802011-02-14 18:35:15 +0000666
Marc Jones8d595692012-03-15 12:55:26 -0600667 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
668 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
669 mmio_basek = mem_hole.hole_startk;
670 reset_memhole = 0;
671 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000672#endif
673
Marc Jones8d595692012-03-15 12:55:26 -0600674 idx = 0x10;
Frank Vibrans39fca802011-02-14 18:35:15 +0000675
Marc Jones8d595692012-03-15 12:55:26 -0600676 struct dram_base_mask_t d;
677 resource_t basek, limitk, sizek; // 4 1T
Frank Vibrans39fca802011-02-14 18:35:15 +0000678
Marc Jones8d595692012-03-15 12:55:26 -0600679 d = get_dram_base_mask(0);
Frank Vibrans39fca802011-02-14 18:35:15 +0000680
Marc Jones8d595692012-03-15 12:55:26 -0600681 if (d.mask & 1) {
682 basek = ((resource_t) ((u64) d.base)) << 8;
683 limitk = (resource_t) (((u64) d.mask << 8) | 0xFFFFFF);
684 printk(BIOS_DEBUG,
685 "adsr: (before) basek = %llx, limitk = %llx.\n", basek,
686 limitk);
Frank Vibrans39fca802011-02-14 18:35:15 +0000687
Marc Jones8d595692012-03-15 12:55:26 -0600688 /* Convert these values to multiples of 1K for ease of math. */
689 basek >>= 10;
690 limitk >>= 10;
691 sizek = limitk - basek + 1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000692
Marc Jones8d595692012-03-15 12:55:26 -0600693 printk(BIOS_DEBUG,
694 "adsr: (after) basek = %llx, limitk = %llx, sizek = %llx.\n",
695 basek, limitk, sizek);
Frank Vibrans39fca802011-02-14 18:35:15 +0000696
Marc Jones8d595692012-03-15 12:55:26 -0600697 /* see if we need a hole from 0xa0000 to 0xbffff */
698 if ((basek < 640) && (sizek > 768)) {
699 printk(BIOS_DEBUG,"adsr - 0xa0000 to 0xbffff resource.\n");
700 ram_resource(dev, (idx | 0), basek, 640 - basek);
701 idx += 0x10;
702 basek = 768;
703 sizek = limitk - 768;
704 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000705
Marc Jones8d595692012-03-15 12:55:26 -0600706 printk(BIOS_DEBUG,
707 "adsr: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
708 mmio_basek, basek, limitk);
Frank Vibrans39fca802011-02-14 18:35:15 +0000709
Marc Jones8d595692012-03-15 12:55:26 -0600710 /* split the region to accomodate pci memory space */
711 if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) {
712 if (basek <= mmio_basek) {
713 unsigned pre_sizek;
714 pre_sizek = mmio_basek - basek;
715 if (pre_sizek > 0) {
716 ram_resource(dev, idx, basek,
717 pre_sizek);
718 idx += 0x10;
719 sizek -= pre_sizek;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300720 if (!ramtop)
721 ramtop = mmio_basek * 1024;
Marc Jones8d595692012-03-15 12:55:26 -0600722 }
Marc Jones8d595692012-03-15 12:55:26 -0600723 basek = mmio_basek;
724 }
725 if ((basek + sizek) <= 4 * 1024 * 1024) {
726 sizek = 0;
727 } else {
728 basek = 4 * 1024 * 1024;
729 sizek -= (4 * 1024 * 1024 - mmio_basek);
730 }
731 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000732
Marc Jones8d595692012-03-15 12:55:26 -0600733 ram_resource(dev, (idx | 0), basek, sizek);
734 idx += 0x10;
Marc Jones8d595692012-03-15 12:55:26 -0600735 printk(BIOS_DEBUG,
736 "%d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", 0,
737 mmio_basek, basek, limitk);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300738 if (!ramtop)
739 ramtop = limitk * 1024;
Marc Jones8d595692012-03-15 12:55:26 -0600740 }
741 printk(BIOS_DEBUG, " adsr - mmio_basek = %lx.\n", mmio_basek);
Frank Vibrans39fca802011-02-14 18:35:15 +0000742
Patrick Georgie1667822012-05-05 15:29:32 +0200743#if CONFIG_GFXUMA
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300744 set_top_of_ram(uma_memory_base);
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300745 uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300746#else
747 set_top_of_ram(ramtop);
Frank Vibrans39fca802011-02-14 18:35:15 +0000748#endif
749
Marc Jones8d595692012-03-15 12:55:26 -0600750 for (link = dev->link_list; link; link = link->next) {
751 if (link->children) {
752 assign_resources(link);
753 }
754 }
755 printk(BIOS_DEBUG, " adsr - leaving this lovely routine.\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000756}
757
zbaof7223732012-04-13 13:42:15 +0800758extern u8 acpi_slp_type;
759
760static void domain_enable_resources(device_t dev)
761{
Marc Jones8d595692012-03-15 12:55:26 -0600762 u32 val;
Kerry Shefeed3292011-08-18 18:03:44 +0800763
764#if CONFIG_AMD_SB_CIMX
zbaof7223732012-04-13 13:42:15 +0800765 #if CONFIG_HAVE_ACPI_RESUME
766 if (acpi_slp_type != 3) {
767 sb_After_Pci_Init();
768 sb_Mid_Post_Init();
769 } else {
770 sb_After_Pci_Restore_Init();
771 }
772 #else
Marc Jones8d595692012-03-15 12:55:26 -0600773 sb_After_Pci_Init();
774 sb_Mid_Post_Init();
zbaof7223732012-04-13 13:42:15 +0800775 #endif
Kerry Shefeed3292011-08-18 18:03:44 +0800776#endif
777
Marc Jones8d595692012-03-15 12:55:26 -0600778 /* Must be called after PCI enumeration and resource allocation */
Mike Loptien58089e82013-01-29 15:45:09 -0700779 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
zbaof7223732012-04-13 13:42:15 +0800780
781#if CONFIG_HAVE_ACPI_RESUME
782 if (acpi_slp_type != 3) {
783 printk(BIOS_DEBUG, "agesawrapper_amdinitmid ");
784 val = agesawrapper_amdinitmid ();
785 if (val)
786 printk(BIOS_DEBUG, "error level: %x \n", val);
787 else
788 printk(BIOS_DEBUG, "passed.\n");
Marc Jones8d595692012-03-15 12:55:26 -0600789 }
zbaof7223732012-04-13 13:42:15 +0800790#else
791 printk(BIOS_DEBUG, "agesawrapper_amdinitmid ");
792 val = agesawrapper_amdinitmid ();
793 if (val)
794 printk(BIOS_DEBUG, "error level: %x \n", val);
795 else
796 printk(BIOS_DEBUG, "passed.\n");
797#endif
efdesign9805a89ab2011-06-20 17:38:49 -0700798
Marc Jones8d595692012-03-15 12:55:26 -0600799 printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000800}
801
Frank Vibrans39fca802011-02-14 18:35:15 +0000802/* Bus related code */
803
Marc Jonesd5c998b2013-01-16 17:14:24 -0700804static void cpu_bus_read_resources(device_t dev)
805{
Frank Vibrans39fca802011-02-14 18:35:15 +0000806}
807
Marc Jonesd5c998b2013-01-16 17:14:24 -0700808static void cpu_bus_set_resources(device_t dev)
809{
Frank Vibrans39fca802011-02-14 18:35:15 +0000810}
efdesign9805a89ab2011-06-20 17:38:49 -0700811
zbaof7223732012-04-13 13:42:15 +0800812static u32 cpu_bus_scan(device_t dev, u32 max)
813{
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300814 struct bus *cpu_bus = dev->link_list;
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000815 device_t cpu;
zbaof7223732012-04-13 13:42:15 +0800816 int apic_id, cores_found;
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000817
zbaof7223732012-04-13 13:42:15 +0800818 /* There is only one node for fam14, but there may be multiple cores. */
819 cpu = dev_find_slot(0, PCI_DEVFN(0x18, 0));
820 if (!cpu)
821 printk(BIOS_ERR, "ERROR: %02x:%02x.0 not found", 0, 0x18);
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000822
zbaof7223732012-04-13 13:42:15 +0800823 cores_found = (pci_read_config32(dev_find_slot(0,PCI_DEVFN(0x18,0x3)), 0xe8) >> 12) & 3;
824 printk(BIOS_DEBUG, " AP siblings=%d\n", cores_found);
825
zbaof7223732012-04-13 13:42:15 +0800826 for (apic_id = 0; apic_id <= cores_found; apic_id++) {
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300827 cpu = add_cpu_device(cpu_bus, apic_id, 1);
828 if (cpu)
829 amd_cpu_topology(cpu, 0, apic_id);
Marc Jones8d595692012-03-15 12:55:26 -0600830 }
zbaof7223732012-04-13 13:42:15 +0800831 return max;
832}
833
834static void cpu_bus_init(device_t dev)
835{
836 initialize_cpus(dev->link_list);
Frank Vibrans39fca802011-02-14 18:35:15 +0000837}
838
Frank Vibrans39fca802011-02-14 18:35:15 +0000839/* North Bridge Structures */
840
841static struct device_operations northbridge_operations = {
Marc Jones8a49ac72013-01-16 17:02:20 -0700842 .read_resources = nb_read_resources,
843 .set_resources = nb_set_resources,
Marc Jones8d595692012-03-15 12:55:26 -0600844 .enable_resources = pci_dev_enable_resources,
845 .init = northbridge_init,
846 .enable = 0,.ops_pci = 0,
Frank Vibrans39fca802011-02-14 18:35:15 +0000847};
848
Frank Vibrans39fca802011-02-14 18:35:15 +0000849static const struct pci_driver northbridge_driver __pci_driver = {
Marc Jones8d595692012-03-15 12:55:26 -0600850 .ops = &northbridge_operations,
851 .vendor = PCI_VENDOR_ID_AMD,
852 .device = 0x1510,
Frank Vibrans39fca802011-02-14 18:35:15 +0000853};
854
efdesign9805a89ab2011-06-20 17:38:49 -0700855struct chip_operations northbridge_amd_agesa_family14_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600856 CHIP_NAME("AMD Family 14h Northbridge")
857 .enable_dev = 0,
Frank Vibrans39fca802011-02-14 18:35:15 +0000858};
859
Frank Vibrans39fca802011-02-14 18:35:15 +0000860/* Root Complex Structures */
861
Frank Vibrans39fca802011-02-14 18:35:15 +0000862static struct device_operations pci_domain_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600863 .read_resources = domain_read_resources,
864 .set_resources = domain_set_resources,
865 .enable_resources = domain_enable_resources,
866 .init = NULL,
867 .scan_bus = pci_domain_scan_bus,
Frank Vibrans39fca802011-02-14 18:35:15 +0000868};
869
Frank Vibrans39fca802011-02-14 18:35:15 +0000870static struct device_operations cpu_bus_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600871 .read_resources = cpu_bus_read_resources,
872 .set_resources = cpu_bus_set_resources,
873 .enable_resources = NULL,
874 .init = cpu_bus_init,
zbaof7223732012-04-13 13:42:15 +0800875 .scan_bus = cpu_bus_scan,
Frank Vibrans39fca802011-02-14 18:35:15 +0000876};
877
Kyösti Mälkki87213b62012-08-27 20:00:33 +0300878static void root_complex_enable_dev(struct device *dev)
879{
880 static int done = 0;
881
882 /* Do not delay UMA setup, as a device on the PCI bus may evaluate
883 the global uma_memory variables already in its enable function. */
884 if (!done) {
885 setup_bsp_ramtop();
886 setup_uma_memory();
887 done = 1;
888 }
889
Marc Jones8d595692012-03-15 12:55:26 -0600890 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800891 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Marc Jones8d595692012-03-15 12:55:26 -0600892 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800893 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Marc Jones8d595692012-03-15 12:55:26 -0600894 dev->ops = &cpu_bus_ops;
895 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000896}
897
efdesign9805a89ab2011-06-20 17:38:49 -0700898struct chip_operations northbridge_amd_agesa_family14_root_complex_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600899 CHIP_NAME("AMD Family 14h Root Complex")
900 .enable_dev = root_complex_enable_dev,
Frank Vibrans39fca802011-02-14 18:35:15 +0000901};