blob: 355a4582fa6780b42b0ce98162999116524671b1 [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
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Frank Vibrans39fca802011-02-14 18:35:15 +000018 */
19
20#include <console/console.h>
21#include <arch/io.h>
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +030022#include <arch/acpi.h>
Kyösti Mälkki68a83df2014-11-26 09:51:14 +020023#include <arch/acpigen.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000024#include <stdint.h>
25#include <device/device.h>
26#include <device/pci.h>
27#include <device/pci_ids.h>
28#include <device/hypertransport.h>
29#include <stdlib.h>
30#include <string.h>
Ronald G. Minnich5079a0d2012-11-27 11:32:38 -080031#include <lib.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000032#include <cpu/cpu.h>
Marc Jones5750ed22012-03-15 13:21:41 -060033#include <cbmem.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000034
35#include <cpu/x86/lapic.h>
Kyösti Mälkki55fff9302012-07-11 08:02:39 +030036#include <cpu/amd/mtrr.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000037
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030038#include <northbridge/amd/agesa/agesawrapper.h>
Kerry Shefeed3292011-08-18 18:03:44 +080039#if CONFIG_AMD_SB_CIMX
40#include <sb_cimx.h>
41#endif
Frank Vibrans39fca802011-02-14 18:35:15 +000042
Frank Vibrans39fca802011-02-14 18:35:15 +000043//#define FX_DEVS NODE_NUMS
44#define FX_DEVS 1
45
46static device_t __f0_dev[FX_DEVS];
47static device_t __f1_dev[FX_DEVS];
48static device_t __f2_dev[FX_DEVS];
49static device_t __f4_dev[FX_DEVS];
Marc Jones8d595692012-03-15 12:55:26 -060050static unsigned fx_devs = 0;
Frank Vibrans39fca802011-02-14 18:35:15 +000051
Edward O'Callaghan541ac592014-11-21 00:37:02 +110052static device_t get_node_pci(u32 nodeid, u32 fn)
Frank Vibrans39fca802011-02-14 18:35:15 +000053{
zbao49bb26a42012-08-03 15:44:42 +080054 if ((CONFIG_CDB + nodeid) < 32) {
55 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
56 } else {
57 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
58 }
Frank Vibrans39fca802011-02-14 18:35:15 +000059}
60
Frank Vibrans39fca802011-02-14 18:35:15 +000061static void get_fx_devs(void)
62{
Marc Jones8d595692012-03-15 12:55:26 -060063 int i;
64 for (i = 0; i < FX_DEVS; i++) {
65 __f0_dev[i] = get_node_pci(i, 0);
66 __f1_dev[i] = get_node_pci(i, 1);
67 __f2_dev[i] = get_node_pci(i, 2);
68 __f4_dev[i] = get_node_pci(i, 4);
69 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
70 fx_devs = i + 1;
71 }
72 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
73 die("Cannot find 0:0x18.[0|1]\n");
74 }
Frank Vibrans39fca802011-02-14 18:35:15 +000075}
76
Frank Vibrans39fca802011-02-14 18:35:15 +000077static u32 f1_read_config32(unsigned reg)
78{
Marc Jones8d595692012-03-15 12:55:26 -060079 if (fx_devs == 0)
80 get_fx_devs();
81 return pci_read_config32(__f1_dev[0], reg);
Frank Vibrans39fca802011-02-14 18:35:15 +000082}
83
Frank Vibrans39fca802011-02-14 18:35:15 +000084static void f1_write_config32(unsigned reg, u32 value)
85{
Marc Jones8d595692012-03-15 12:55:26 -060086 int i;
87 if (fx_devs == 0)
88 get_fx_devs();
89 for (i = 0; i < fx_devs; i++) {
90 device_t dev;
91 dev = __f1_dev[i];
92 if (dev && dev->enabled) {
93 pci_write_config32(dev, reg, value);
94 }
95 }
Frank Vibrans39fca802011-02-14 18:35:15 +000096}
97
Frank Vibrans39fca802011-02-14 18:35:15 +000098static u32 amdfam14_nodeid(device_t dev)
99{
Marc Jones8d595692012-03-15 12:55:26 -0600100 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
Frank Vibrans39fca802011-02-14 18:35:15 +0000101}
102
Frank Vibrans39fca802011-02-14 18:35:15 +0000103#include "amdfam14_conf.c"
104
Frank Vibrans39fca802011-02-14 18:35:15 +0000105static void northbridge_init(device_t dev)
106{
Marc Jones8d595692012-03-15 12:55:26 -0600107 printk(BIOS_DEBUG, "Northbridge init\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000108}
109
Frank Vibrans39fca802011-02-14 18:35:15 +0000110static void set_vga_enable_reg(u32 nodeid, u32 linkn)
111{
Marc Jones8d595692012-03-15 12:55:26 -0600112 u32 val;
Frank Vibrans39fca802011-02-14 18:35:15 +0000113
Marc Jones8d595692012-03-15 12:55:26 -0600114 val = 1 | (nodeid << 4) | (linkn << 12);
115 /* it will routing (1)mmio 0xa0000:0xbffff (2) io 0x3b0:0x3bb,
116 0x3c0:0x3df */
117 f1_write_config32(0xf4, val);
Frank Vibrans39fca802011-02-14 18:35:15 +0000118
119}
120
Frank Vibrans39fca802011-02-14 18:35:15 +0000121static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
Marc Jones8d595692012-03-15 12:55:26 -0600122 unsigned goal_link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000123{
Marc Jones8d595692012-03-15 12:55:26 -0600124 struct resource *res;
125 unsigned nodeid, link = 0;
126 int result;
127 res = 0;
128 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
129 device_t dev;
130 dev = __f0_dev[nodeid];
131 if (!dev)
132 continue;
133 for (link = 0; !res && (link < 8); link++) {
134 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
135 }
136 }
137 result = 2;
138 if (res) {
139 result = 0;
140 if ((goal_link == (link - 1)) &&
141 (goal_nodeid == (nodeid - 1)) && (res->flags <= 1)) {
142 result = 1;
143 }
144 }
145 return result;
Frank Vibrans39fca802011-02-14 18:35:15 +0000146}
147
Marc Jones8d595692012-03-15 12:55:26 -0600148static struct resource *amdfam14_find_iopair(device_t dev, unsigned nodeid,
149 unsigned link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000150{
Marc Jones8d595692012-03-15 12:55:26 -0600151 struct resource *resource;
152 u32 result, reg;
153 resource = 0;
154 reg = 0;
155 result = reg_useable(0xc0, dev, nodeid, link);
156 if (result >= 1) {
157 /* I have been allocated this one */
158 reg = 0xc0;
159 }
160 /* Ext conf space */
161 if (!reg) {
162 /* Because of Extend conf space, we will never run out of reg,
163 * but we need one index to differ them. So ,same node and same
164 * link can have multi range
165 */
166 u32 index = get_io_addr_index(nodeid, link);
167 reg = 0x110 + (index << 24) + (4 << 20); // index could be 0, 255
168 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000169
Marc Jones8d595692012-03-15 12:55:26 -0600170 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
Frank Vibrans39fca802011-02-14 18:35:15 +0000171
Marc Jones8d595692012-03-15 12:55:26 -0600172 return resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000173}
174
Marc Jones8d595692012-03-15 12:55:26 -0600175static struct resource *amdfam14_find_mempair(device_t dev, u32 nodeid,
176 u32 link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000177{
Marc Jones8d595692012-03-15 12:55:26 -0600178 struct resource *resource;
179 u32 free_reg, reg;
180 resource = 0;
181 free_reg = 0;
182 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
183 int result;
184 result = reg_useable(reg, dev, nodeid, link);
185 if (result == 1) {
186 /* I have been allocated this one */
187 break;
188 } else if (result > 1) {
189 /* I have a free register pair */
190 free_reg = reg;
191 }
192 }
193 if (reg > 0xb8) {
194 reg = free_reg;
195 }
196 /* Ext conf space */
197 if (!reg) {
198 /* Because of Extend conf space, we will never run out of reg,
199 * but we need one index to differ them. So ,same node and same
200 * link can have multi range
201 */
202 u32 index = get_mmio_addr_index(nodeid, link);
203 reg = 0x110 + (index << 24) + (6 << 20); // index could be 0, 63
Frank Vibrans39fca802011-02-14 18:35:15 +0000204
Marc Jones8d595692012-03-15 12:55:26 -0600205 }
206 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
207 return resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000208}
209
Frank Vibrans39fca802011-02-14 18:35:15 +0000210static void amdfam14_link_read_bases(device_t dev, u32 nodeid, u32 link)
211{
Marc Jones8d595692012-03-15 12:55:26 -0600212 struct resource *resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000213
Marc Jones8d595692012-03-15 12:55:26 -0600214 /* Initialize the io space constraints on the current bus */
215 resource = amdfam14_find_iopair(dev, nodeid, link);
216 if (resource) {
217 u32 align;
Kyösti Mälkkiac7402d2014-12-14 08:30:17 +0200218 align = log2(HT_IO_HOST_ALIGN);
Marc Jones8d595692012-03-15 12:55:26 -0600219 resource->base = 0;
220 resource->size = 0;
221 resource->align = align;
222 resource->gran = align;
223 resource->limit = 0xffffUL;
224 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
225 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000226
Marc Jones8d595692012-03-15 12:55:26 -0600227 /* Initialize the prefetchable memory constraints on the current bus */
228 resource = amdfam14_find_mempair(dev, nodeid, link);
229 if (resource) {
230 resource->base = 0;
231 resource->size = 0;
232 resource->align = log2(HT_MEM_HOST_ALIGN);
233 resource->gran = log2(HT_MEM_HOST_ALIGN);
234 resource->limit = 0xffffffffffULL;
235 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
236 resource->flags |= IORESOURCE_BRIDGE;
Marc Jones8d595692012-03-15 12:55:26 -0600237 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000238
Marc Jones8d595692012-03-15 12:55:26 -0600239 /* Initialize the memory constraints on the current bus */
240 resource = amdfam14_find_mempair(dev, nodeid, link);
241 if (resource) {
242 resource->base = 0;
243 resource->size = 0;
244 resource->align = log2(HT_MEM_HOST_ALIGN);
245 resource->gran = log2(HT_MEM_HOST_ALIGN);
246 resource->limit = 0xffffffffffULL;
247 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
Marc Jones8d595692012-03-15 12:55:26 -0600248 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000249}
250
251static u32 my_find_pci_tolm(struct bus *bus, u32 tolm)
252{
Marc Jones8d595692012-03-15 12:55:26 -0600253 struct resource *min;
254 min = 0;
255 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test,
256 &min);
257 if (min && tolm > min->base) {
258 tolm = min->base;
259 }
260 return tolm;
Frank Vibrans39fca802011-02-14 18:35:15 +0000261}
262
263#if CONFIG_HW_MEM_HOLE_SIZEK != 0
264
265struct hw_mem_hole_info {
Marc Jones8d595692012-03-15 12:55:26 -0600266 unsigned hole_startk;
267 int node_id;
Frank Vibrans39fca802011-02-14 18:35:15 +0000268};
269
270static struct hw_mem_hole_info get_hw_mem_hole_info(void)
271{
Marc Jones8d595692012-03-15 12:55:26 -0600272 struct hw_mem_hole_info mem_hole;
Frank Vibrans39fca802011-02-14 18:35:15 +0000273
Marc Jones8d595692012-03-15 12:55:26 -0600274 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
275 mem_hole.node_id = -1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000276
Marc Jones8d595692012-03-15 12:55:26 -0600277 struct dram_base_mask_t d;
278 u32 hole;
279 d = get_dram_base_mask(0);
280 if (d.mask & 1) {
281 hole = pci_read_config32(__f1_dev[0], 0xf0);
282 if (hole & 1) { // we find the hole
283 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
284 mem_hole.node_id = 0; // record the node No with hole
285 }
286 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000287#if 0
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300288 /* We need to double check if there is special set on base reg and limit reg
289 * are not continuous instead of hole, it will find out its hole_startk.
Marc Jones8d595692012-03-15 12:55:26 -0600290 */
291 if (mem_hole.node_id == -1) {
292 resource_t limitk_pri = 0;
293 struct dram_base_mask_t d;
294 resource_t base_k, limit_k;
295 d = get_dram_base_mask(0);
296 if (d.base & 1) {
297 base_k = ((resource_t) (d.base & 0x1fffff00)) << 9;
298 if (base_k <= 4 * 1024 * 1024) {
299 if (limitk_pri != base_k) { // we find the hole
300 mem_hole.hole_startk = (unsigned)limitk_pri; // must be below 4G
301 mem_hole.node_id = 0;
302 }
303 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000304
Marc Jones8d595692012-03-15 12:55:26 -0600305 limit_k =
306 ((resource_t) ((d.mask + 0x00000100) & 0x1fffff00))
307 << 9;
308 limitk_pri = limit_k;
309 }
310 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000311#endif
efdesign9805a89ab2011-06-20 17:38:49 -0700312
Marc Jones8d595692012-03-15 12:55:26 -0600313 return mem_hole;
Frank Vibrans39fca802011-02-14 18:35:15 +0000314}
315#endif
316
Marc Jones8a49ac72013-01-16 17:02:20 -0700317static void nb_read_resources(device_t dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000318{
Marc Jones8d595692012-03-15 12:55:26 -0600319 u32 nodeid;
320 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000321
Mike Loptien58089e82013-01-29 15:45:09 -0700322 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000323
Marc Jones8d595692012-03-15 12:55:26 -0600324 nodeid = amdfam14_nodeid(dev);
325 for (link = dev->link_list; link; link = link->next) {
326 if (link->children) {
327 amdfam14_link_read_bases(dev, nodeid, link->link_num);
328 }
329 }
Marc Jonesd5c998b2013-01-16 17:14:24 -0700330
331 /*
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800332 * This MMCONF resource must be reserved in the PCI domain.
Marc Jonesd5c998b2013-01-16 17:14:24 -0700333 * It is not honored by the coreboot resource allocator if it is in
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800334 * the CPU_CLUSTER.
Marc Jonesd5c998b2013-01-16 17:14:24 -0700335 */
336#if CONFIG_MMCONF_SUPPORT
337 struct resource *resource = new_resource(dev, 0xc0010058);
338 resource->base = CONFIG_MMCONF_BASE_ADDRESS;
339 resource->size = CONFIG_MMCONF_BUS_NUMBER * 4096 * 256;
340 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
341 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
342#endif
Frank Vibrans39fca802011-02-14 18:35:15 +0000343}
344
Marc Jones8d595692012-03-15 12:55:26 -0600345static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
Frank Vibrans39fca802011-02-14 18:35:15 +0000346{
Marc Jones8d595692012-03-15 12:55:26 -0600347 resource_t rbase, rend;
348 unsigned reg, link_num;
349 char buf[50];
Frank Vibrans39fca802011-02-14 18:35:15 +0000350
Mike Loptien58089e82013-01-29 15:45:09 -0700351 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000352
Marc Jones8d595692012-03-15 12:55:26 -0600353 /* Make certain the resource has actually been set */
354 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
355 return;
356 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000357
Marc Jones8d595692012-03-15 12:55:26 -0600358 /* If I have already stored this resource don't worry about it */
359 if (resource->flags & IORESOURCE_STORED) {
360 return;
361 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000362
Marc Jones8d595692012-03-15 12:55:26 -0600363 /* Only handle PCI memory and IO resources */
364 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
365 return;
Frank Vibrans39fca802011-02-14 18:35:15 +0000366
Marc Jones8d595692012-03-15 12:55:26 -0600367 /* Ensure I am actually looking at a resource of function 1 */
368 if ((resource->index & 0xffff) < 0x1000) {
369 return;
370 }
371 /* Get the base address */
372 rbase = resource->base;
Frank Vibrans39fca802011-02-14 18:35:15 +0000373
Marc Jones8d595692012-03-15 12:55:26 -0600374 /* Get the limit (rounded up) */
375 rend = resource_end(resource);
Frank Vibrans39fca802011-02-14 18:35:15 +0000376
Marc Jones8d595692012-03-15 12:55:26 -0600377 /* Get the register and link */
378 reg = resource->index & 0xfff; // 4k
379 link_num = IOINDEX_LINK(resource->index);
Frank Vibrans39fca802011-02-14 18:35:15 +0000380
Marc Jones8d595692012-03-15 12:55:26 -0600381 if (resource->flags & IORESOURCE_IO) {
382 set_io_addr_reg(dev, nodeid, link_num, reg, rbase >> 8,
383 rend >> 8);
384 } else if (resource->flags & IORESOURCE_MEM) {
385 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >> 24),
386 rbase >> 8, rend >> 8, 1); // [39:8]
387 }
388 resource->flags |= IORESOURCE_STORED;
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100389 snprintf(buf, sizeof (buf), " <node %x link %x>", nodeid, link_num);
Marc Jones8d595692012-03-15 12:55:26 -0600390 report_resource_stored(dev, resource, buf);
Frank Vibrans39fca802011-02-14 18:35:15 +0000391}
392
efdesign983f5ebd62011-09-14 13:47:17 -0600393#if CONFIG_CONSOLE_VGA_MULTI
Marc Jones8d595692012-03-15 12:55:26 -0600394extern device_t vga_pri; // the primary vga device, defined in device.c
Frank Vibrans39fca802011-02-14 18:35:15 +0000395#endif
396
397static void create_vga_resource(device_t dev, unsigned nodeid)
398{
Marc Jones8d595692012-03-15 12:55:26 -0600399 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000400
Mike Loptien58089e82013-01-29 15:45:09 -0700401 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000402
Marc Jones8d595692012-03-15 12:55:26 -0600403 /* find out which link the VGA card is connected,
404 * we only deal with the 'first' vga card */
405 for (link = dev->link_list; link; link = link->next) {
406 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
efdesign983f5ebd62011-09-14 13:47:17 -0600407#if CONFIG_CONSOLE_VGA_MULTI
Marc Jones8d595692012-03-15 12:55:26 -0600408 printk(BIOS_DEBUG,
409 "VGA: vga_pri bus num = %d bus range [%d,%d]\n",
410 vga_pri->bus->secondary, link->secondary,
411 link->subordinate);
412 /* We need to make sure the vga_pri is under the link */
413 if ((vga_pri->bus->secondary >= link->secondary) &&
414 (vga_pri->bus->secondary <= link->subordinate))
Frank Vibrans39fca802011-02-14 18:35:15 +0000415#endif
Marc Jones8d595692012-03-15 12:55:26 -0600416 break;
417 }
418 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000419
Marc Jones8d595692012-03-15 12:55:26 -0600420 /* no VGA card installed */
421 if (link == NULL)
422 return;
Frank Vibrans39fca802011-02-14 18:35:15 +0000423
Marc Jones8d595692012-03-15 12:55:26 -0600424 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n",
425 dev_path(dev), nodeid, link->link_num);
426 set_vga_enable_reg(nodeid, link->link_num);
Frank Vibrans39fca802011-02-14 18:35:15 +0000427}
428
Marc Jones8a49ac72013-01-16 17:02:20 -0700429static void nb_set_resources(device_t dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000430{
Marc Jones8d595692012-03-15 12:55:26 -0600431 unsigned nodeid;
432 struct bus *bus;
433 struct resource *res;
Frank Vibrans39fca802011-02-14 18:35:15 +0000434
Mike Loptien58089e82013-01-29 15:45:09 -0700435 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
efdesign9805a89ab2011-06-20 17:38:49 -0700436
Marc Jones8d595692012-03-15 12:55:26 -0600437 /* Find the nodeid */
438 nodeid = amdfam14_nodeid(dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000439
Marc Jones8d595692012-03-15 12:55:26 -0600440 create_vga_resource(dev, nodeid);
Frank Vibrans39fca802011-02-14 18:35:15 +0000441
Marc Jones8d595692012-03-15 12:55:26 -0600442 /* Set each resource we have found */
443 for (res = dev->resource_list; res; res = res->next) {
444 set_resource(dev, res, nodeid);
445 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000446
Marc Jones8d595692012-03-15 12:55:26 -0600447 for (bus = dev->link_list; bus; bus = bus->next) {
448 if (bus->children) {
449 assign_resources(bus);
450 }
451 }
Marc Jonesd5c998b2013-01-16 17:14:24 -0700452
453 /* Print the MMCONF region if it has been reserved. */
454 res = find_resource(dev, 0xc0010058);
455 if (res) {
456 report_resource_stored(dev, res, " <mmconfig>");
457 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000458}
459
Frank Vibrans39fca802011-02-14 18:35:15 +0000460/* Domain/Root Complex related code */
461
462static void domain_read_resources(device_t dev)
463{
Marc Jones8d595692012-03-15 12:55:26 -0600464 unsigned reg;
Frank Vibrans39fca802011-02-14 18:35:15 +0000465
Mike Loptien58089e82013-01-29 15:45:09 -0700466 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000467
Marc Jones8d595692012-03-15 12:55:26 -0600468 /* Find the already assigned resource pairs */
469 get_fx_devs();
470 for (reg = 0x80; reg <= 0xc0; reg += 0x08) {
471 u32 base, limit;
472 base = f1_read_config32(reg);
473 limit = f1_read_config32(reg + 0x04);
474 /* Is this register allocated? */
475 if ((base & 3) != 0) {
476 unsigned nodeid, reg_link;
477 device_t reg_dev;
478 if (reg < 0xc0) { // mmio
479 nodeid = (limit & 0xf) + (base & 0x30);
480 } else { // io
481 nodeid = (limit & 0xf) + ((base >> 4) & 0x30);
482 }
483 reg_link = (limit >> 4) & 7;
484 reg_dev = __f0_dev[nodeid];
485 if (reg_dev) {
486 /* Reserve the resource */
487 struct resource *res;
488 res =
489 new_resource(reg_dev,
490 IOINDEX(0x1000 + reg,
491 reg_link));
492 if (res) {
493 res->flags = 1;
494 }
495 }
496 }
497 }
498 /* FIXME: do we need to check extend conf space?
499 I don't believe that much preset value */
Frank Vibrans39fca802011-02-14 18:35:15 +0000500
Patrick Georgie1667822012-05-05 15:29:32 +0200501#if !CONFIG_PCI_64BIT_PREF_MEM
Marc Jones8d595692012-03-15 12:55:26 -0600502 pci_domain_read_resources(dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000503#else
Marc Jones8d595692012-03-15 12:55:26 -0600504 struct bus *link;
505 struct resource *resource;
506 for (link = dev->link_list; link; link = link->next) {
507 /* Initialize the system wide io space constraints */
508 resource = new_resource(dev, 0 | (link->link_num << 2));
509 resource->base = 0x400;
510 resource->limit = 0xffffUL;
511 resource->flags = IORESOURCE_IO;
Frank Vibrans39fca802011-02-14 18:35:15 +0000512
Marc Jones8d595692012-03-15 12:55:26 -0600513 /* Initialize the system wide prefetchable memory resources constraints */
514 resource = new_resource(dev, 1 | (link->link_num << 2));
515 resource->limit = 0xfcffffffffULL;
516 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
Frank Vibrans39fca802011-02-14 18:35:15 +0000517
Marc Jones8d595692012-03-15 12:55:26 -0600518 /* Initialize the system wide memory resources constraints */
519 resource = new_resource(dev, 2 | (link->link_num << 2));
520 resource->limit = 0xfcffffffffULL;
521 resource->flags = IORESOURCE_MEM;
522 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000523#endif
524}
525
Kyösti Mälkki6b5eb1c2012-07-19 19:26:43 +0300526static void setup_uma_memory(void)
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300527{
528#if CONFIG_GFXUMA
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300529 uint32_t topmem = (uint32_t) bsp_topmem();
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300530 uint32_t sys_mem;
531
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300532 /* refer to UMA Size Consideration in Family14h BKDG. */
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300533 sys_mem = topmem + 0x1000000; // Ignore 16MB allocated for C6 when finding UMA size, refer MemNGetUmaSizeON()
534 if ((bsp_topmem2()>>32) || (sys_mem >= 0x80000000)) {
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300535 uma_memory_size = 0x18000000; /* >= 2G memory, 384M recommended UMA */
536 }
537 else {
538 if (sys_mem >= 0x40000000) {
539 uma_memory_size = 0x10000000; /* >= 1G memory, 256M recommended UMA */
540 } else {
541 uma_memory_size = 0x4000000; /* <1G memory, 64M recommended UMA */
542 }
543 }
544
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300545 uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300546 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
547 __func__, uma_memory_size, uma_memory_base);
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300548#endif
549}
550
Frank Vibrans39fca802011-02-14 18:35:15 +0000551static void domain_set_resources(device_t dev)
552{
Mike Loptien58089e82013-01-29 15:45:09 -0700553 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Marc Jones8d595692012-03-15 12:55:26 -0600554 printk(BIOS_DEBUG, " amsr - incoming dev = %08x\n", (u32) dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000555
Patrick Georgie1667822012-05-05 15:29:32 +0200556#if CONFIG_PCI_64BIT_PREF_MEM
Marc Jones8d595692012-03-15 12:55:26 -0600557 struct resource *io, *mem1, *mem2;
558 struct resource *res;
Frank Vibrans39fca802011-02-14 18:35:15 +0000559#endif
Marc Jones8d595692012-03-15 12:55:26 -0600560 unsigned long mmio_basek;
561 u32 pci_tolm;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300562 u64 ramtop = 0;
Marc Jones8d595692012-03-15 12:55:26 -0600563 int idx;
564 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000565#if CONFIG_HW_MEM_HOLE_SIZEK != 0
Marc Jones8d595692012-03-15 12:55:26 -0600566 struct hw_mem_hole_info mem_hole;
567 u32 reset_memhole = 1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000568#endif
569
Patrick Georgie1667822012-05-05 15:29:32 +0200570#if CONFIG_PCI_64BIT_PREF_MEM
Frank Vibrans39fca802011-02-14 18:35:15 +0000571
Marc Jones8d595692012-03-15 12:55:26 -0600572 printk(BIOS_DEBUG, "adsr - CONFIG_PCI_64BIT_PREF_MEM is true.\n");
573 for (link = dev->link_list; link; link = link->next) {
574 /* Now reallocate the pci resources memory with the
575 * highest addresses I can manage.
576 */
577 mem1 = find_resource(dev, 1 | (link->link_num << 2));
578 mem2 = find_resource(dev, 2 | (link->link_num << 2));
Frank Vibrans39fca802011-02-14 18:35:15 +0000579
Marc Jones8d595692012-03-15 12:55:26 -0600580 printk(BIOS_DEBUG,
581 "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
582 (u32) (mem1->base), (u32) (mem1->limit),
583 (u32) (mem1->size), u32) (mem1->align));
584 printk(BIOS_DEBUG,
585 "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
586 (u32) (mem2->base), (u32) (mem2->limit),
587 (u32) (mem2->size), (u32) (mem2->align));
Frank Vibrans39fca802011-02-14 18:35:15 +0000588
Marc Jones8d595692012-03-15 12:55:26 -0600589 /* See if both resources have roughly the same limits */
590 if (((mem1->limit <= 0xffffffff) && (mem2->limit <= 0xffffffff))
591 || ((mem1->limit > 0xffffffff)
592 && (mem2->limit > 0xffffffff))) {
593 /* If so place the one with the most stringent alignment first
594 */
595 if (mem2->align > mem1->align) {
596 struct resource *tmp;
597 tmp = mem1;
598 mem1 = mem2;
599 mem2 = tmp;
600 }
601 /* Now place the memory as high up as it will go */
602 mem2->base = resource_max(mem2);
603 mem1->limit = mem2->base - 1;
604 mem1->base = resource_max(mem1);
605 } else {
606 /* Place the resources as high up as they will go */
607 mem2->base = resource_max(mem2);
608 mem1->base = resource_max(mem1);
609 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000610
Marc Jones8d595692012-03-15 12:55:26 -0600611 printk(BIOS_DEBUG,
612 "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
613 mem1->base, mem1->limit, mem1->size, mem1->align);
614 printk(BIOS_DEBUG,
615 "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
616 mem2->base, mem2->limit, mem2->size, mem2->align);
617 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000618
Marc Jones8d595692012-03-15 12:55:26 -0600619 for (res = &dev->resource_list; res; res = res->next) {
620 res->flags |= IORESOURCE_ASSIGNED;
621 res->flags |= IORESOURCE_STORED;
622 report_resource_stored(dev, res, "");
623 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000624#endif
625
Marc Jones8d595692012-03-15 12:55:26 -0600626 pci_tolm = 0xffffffffUL;
627 for (link = dev->link_list; link; link = link->next) {
628 pci_tolm = my_find_pci_tolm(link, pci_tolm);
629 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000630
Marc Jones8d595692012-03-15 12:55:26 -0600631 // FIXME handle interleaved nodes. If you fix this here, please fix
632 // amdk8, too.
633 mmio_basek = pci_tolm >> 10;
634 /* Round mmio_basek to something the processor can support */
635 mmio_basek &= ~((1 << 6) - 1);
Frank Vibrans39fca802011-02-14 18:35:15 +0000636
Marc Jones8d595692012-03-15 12:55:26 -0600637 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
638 // MMIO hole. If you fix this here, please fix amdk8, too.
639 /* Round the mmio hole to 64M */
640 mmio_basek &= ~((64 * 1024) - 1);
Frank Vibrans39fca802011-02-14 18:35:15 +0000641
642#if CONFIG_HW_MEM_HOLE_SIZEK != 0
643/* if the hw mem hole is already set in raminit stage, here we will compare
644 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
645 * use hole_basek as mmio_basek and we don't need to reset hole.
646 * otherwise We reset the hole to the mmio_basek
647 */
648
Marc Jones8d595692012-03-15 12:55:26 -0600649 mem_hole = get_hw_mem_hole_info();
Frank Vibrans39fca802011-02-14 18:35:15 +0000650
Marc Jones8d595692012-03-15 12:55:26 -0600651 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
652 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
653 mmio_basek = mem_hole.hole_startk;
654 reset_memhole = 0;
655 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000656#endif
657
Marc Jones8d595692012-03-15 12:55:26 -0600658 idx = 0x10;
Frank Vibrans39fca802011-02-14 18:35:15 +0000659
Marc Jones8d595692012-03-15 12:55:26 -0600660 struct dram_base_mask_t d;
661 resource_t basek, limitk, sizek; // 4 1T
Frank Vibrans39fca802011-02-14 18:35:15 +0000662
Marc Jones8d595692012-03-15 12:55:26 -0600663 d = get_dram_base_mask(0);
Frank Vibrans39fca802011-02-14 18:35:15 +0000664
Marc Jones8d595692012-03-15 12:55:26 -0600665 if (d.mask & 1) {
666 basek = ((resource_t) ((u64) d.base)) << 8;
667 limitk = (resource_t) (((u64) d.mask << 8) | 0xFFFFFF);
668 printk(BIOS_DEBUG,
669 "adsr: (before) basek = %llx, limitk = %llx.\n", basek,
670 limitk);
Frank Vibrans39fca802011-02-14 18:35:15 +0000671
Marc Jones8d595692012-03-15 12:55:26 -0600672 /* Convert these values to multiples of 1K for ease of math. */
673 basek >>= 10;
674 limitk >>= 10;
675 sizek = limitk - basek + 1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000676
Marc Jones8d595692012-03-15 12:55:26 -0600677 printk(BIOS_DEBUG,
678 "adsr: (after) basek = %llx, limitk = %llx, sizek = %llx.\n",
679 basek, limitk, sizek);
Frank Vibrans39fca802011-02-14 18:35:15 +0000680
Marc Jones8d595692012-03-15 12:55:26 -0600681 /* see if we need a hole from 0xa0000 to 0xbffff */
682 if ((basek < 640) && (sizek > 768)) {
683 printk(BIOS_DEBUG,"adsr - 0xa0000 to 0xbffff resource.\n");
684 ram_resource(dev, (idx | 0), basek, 640 - basek);
685 idx += 0x10;
686 basek = 768;
687 sizek = limitk - 768;
688 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000689
Marc Jones8d595692012-03-15 12:55:26 -0600690 printk(BIOS_DEBUG,
691 "adsr: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
692 mmio_basek, basek, limitk);
Frank Vibrans39fca802011-02-14 18:35:15 +0000693
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300694 /* split the region to accommodate pci memory space */
Marc Jones8d595692012-03-15 12:55:26 -0600695 if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) {
696 if (basek <= mmio_basek) {
697 unsigned pre_sizek;
698 pre_sizek = mmio_basek - basek;
699 if (pre_sizek > 0) {
700 ram_resource(dev, idx, basek,
701 pre_sizek);
702 idx += 0x10;
703 sizek -= pre_sizek;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300704 if (!ramtop)
705 ramtop = mmio_basek * 1024;
Marc Jones8d595692012-03-15 12:55:26 -0600706 }
Marc Jones8d595692012-03-15 12:55:26 -0600707 basek = mmio_basek;
708 }
709 if ((basek + sizek) <= 4 * 1024 * 1024) {
710 sizek = 0;
711 } else {
712 basek = 4 * 1024 * 1024;
713 sizek -= (4 * 1024 * 1024 - mmio_basek);
714 }
715 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000716
Marc Jones8d595692012-03-15 12:55:26 -0600717 ram_resource(dev, (idx | 0), basek, sizek);
718 idx += 0x10;
Marc Jones8d595692012-03-15 12:55:26 -0600719 printk(BIOS_DEBUG,
720 "%d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", 0,
721 mmio_basek, basek, limitk);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300722 if (!ramtop)
723 ramtop = limitk * 1024;
Marc Jones8d595692012-03-15 12:55:26 -0600724 }
725 printk(BIOS_DEBUG, " adsr - mmio_basek = %lx.\n", mmio_basek);
Frank Vibrans39fca802011-02-14 18:35:15 +0000726
Patrick Georgie1667822012-05-05 15:29:32 +0200727#if CONFIG_GFXUMA
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300728 set_top_of_ram(uma_memory_base);
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300729 uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300730#else
731 set_top_of_ram(ramtop);
Frank Vibrans39fca802011-02-14 18:35:15 +0000732#endif
733
Marc Jones8d595692012-03-15 12:55:26 -0600734 for (link = dev->link_list; link; link = link->next) {
735 if (link->children) {
736 assign_resources(link);
737 }
738 }
739 printk(BIOS_DEBUG, " adsr - leaving this lovely routine.\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000740}
741
zbaof7223732012-04-13 13:42:15 +0800742static void domain_enable_resources(device_t dev)
743{
Kerry Shefeed3292011-08-18 18:03:44 +0800744#if CONFIG_AMD_SB_CIMX
Kyösti Mälkkic551caa2014-06-20 12:31:23 +0300745 if (!acpi_is_wakeup_s3()) {
zbaof7223732012-04-13 13:42:15 +0800746 sb_After_Pci_Init();
747 sb_Mid_Post_Init();
748 } else {
749 sb_After_Pci_Restore_Init();
750 }
Kerry Shefeed3292011-08-18 18:03:44 +0800751#endif
752
Marc Jones8d595692012-03-15 12:55:26 -0600753 /* Must be called after PCI enumeration and resource allocation */
Mike Loptien58089e82013-01-29 15:45:09 -0700754 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
zbaof7223732012-04-13 13:42:15 +0800755
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300756 if (!acpi_is_wakeup_s3()) {
757 /* Enable MMIO on AMD CPU Address Map Controller */
Kyösti Mälkki48518f02014-11-25 14:20:57 +0200758 amd_initcpuio();
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300759
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300760 agesawrapper_amdinitmid();
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300761 }
efdesign9805a89ab2011-06-20 17:38:49 -0700762
Marc Jones8d595692012-03-15 12:55:26 -0600763 printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000764}
765
Frank Vibrans39fca802011-02-14 18:35:15 +0000766/* Bus related code */
767
Edward O'Callaghan2837ab22014-11-06 08:57:40 +1100768static u32 cpu_bus_scan(struct device *dev, u32 max)
zbaof7223732012-04-13 13:42:15 +0800769{
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300770 struct bus *cpu_bus = dev->link_list;
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000771 device_t cpu;
zbaof7223732012-04-13 13:42:15 +0800772 int apic_id, cores_found;
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000773
zbaof7223732012-04-13 13:42:15 +0800774 /* There is only one node for fam14, but there may be multiple cores. */
775 cpu = dev_find_slot(0, PCI_DEVFN(0x18, 0));
776 if (!cpu)
777 printk(BIOS_ERR, "ERROR: %02x:%02x.0 not found", 0, 0x18);
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000778
zbaof7223732012-04-13 13:42:15 +0800779 cores_found = (pci_read_config32(dev_find_slot(0,PCI_DEVFN(0x18,0x3)), 0xe8) >> 12) & 3;
780 printk(BIOS_DEBUG, " AP siblings=%d\n", cores_found);
781
zbaof7223732012-04-13 13:42:15 +0800782 for (apic_id = 0; apic_id <= cores_found; apic_id++) {
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300783 cpu = add_cpu_device(cpu_bus, apic_id, 1);
784 if (cpu)
785 amd_cpu_topology(cpu, 0, apic_id);
Marc Jones8d595692012-03-15 12:55:26 -0600786 }
zbaof7223732012-04-13 13:42:15 +0800787 return max;
788}
789
790static void cpu_bus_init(device_t dev)
791{
792 initialize_cpus(dev->link_list);
Frank Vibrans39fca802011-02-14 18:35:15 +0000793}
794
Frank Vibrans39fca802011-02-14 18:35:15 +0000795/* North Bridge Structures */
796
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200797static void northbridge_fill_ssdt_generator(void)
798{
799 msr_t msr;
800 char pscope[] = "\\_SB.PCI0";
801
802 acpigen_write_scope(pscope);
803 msr = rdmsr(TOP_MEM);
804 acpigen_write_name_dword("TOM1", msr.lo);
805 msr = rdmsr(TOP_MEM2);
806 /*
807 * Since XP only implements parts of ACPI 2.0, we can't use a qword
808 * here.
809 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
810 * slide 22ff.
811 * Shift value right by 20 bit to make it fit into 32bit,
812 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
813 */
814 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
815 acpigen_pop_len();
816}
817
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100818static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200819{
820 void *addr, *current;
821
822 /* Skip the HEST header. */
823 current = (void *)(hest + 1);
824
825 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
826 if (addr != NULL)
827 current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
828
829 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
830 if (addr != NULL)
831 current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
832
833 return (unsigned long)current;
834}
835
836static unsigned long agesa_write_acpi_tables(unsigned long current,
837 acpi_rsdp_t *rsdp)
838{
839 acpi_srat_t *srat;
840 acpi_slit_t *slit;
841 acpi_header_t *ssdt;
842 acpi_header_t *alib;
843 acpi_hest_t *hest;
844
845 /* HEST */
846 current = ALIGN(current, 8);
847 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100848 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200849 acpi_add_table(rsdp, (void *)current);
850 current += ((acpi_header_t *)current)->length;
851
852 /* SRAT */
853 current = ALIGN(current, 8);
854 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
855 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
856 if (srat != NULL) {
857 memcpy((void *)current, srat, srat->header.length);
858 srat = (acpi_srat_t *) current;
859 current += srat->header.length;
860 acpi_add_table(rsdp, srat);
861 }
862 else {
863 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
864 }
865
866 /* SLIT */
867 current = ALIGN(current, 8);
868 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
869 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
870 if (slit != NULL) {
871 memcpy((void *)current, slit, slit->header.length);
872 slit = (acpi_slit_t *) current;
873 current += slit->header.length;
874 acpi_add_table(rsdp, slit);
875 }
876 else {
877 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
878 }
879
880 /* SSDT */
881 current = ALIGN(current, 16);
882 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
883 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
884 if (alib != NULL) {
885 memcpy((void *)current, alib, alib->length);
886 alib = (acpi_header_t *) current;
887 current += alib->length;
888 acpi_add_table(rsdp, (void *)alib);
889 } else {
890 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
891 }
892
893 /* The DSDT needs additional work for the AGESA SSDT Pstate table */
894 /* Keep the comment for a while. */
895 current = ALIGN(current, 16);
896 printk(BIOS_DEBUG, "ACPI: * AGESA SSDT Pstate at %lx\n", current);
897 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
898 if (ssdt != NULL) {
899 memcpy((void *)current, ssdt, ssdt->length);
900 ssdt = (acpi_header_t *) current;
901 current += ssdt->length;
902 acpi_add_table(rsdp,ssdt);
903 } else {
904 printk(BIOS_DEBUG, " AGESA SSDT Pstate table NULL. Skipping.\n");
905 }
906
907 return current;
908}
909
Frank Vibrans39fca802011-02-14 18:35:15 +0000910static struct device_operations northbridge_operations = {
Marc Jones8a49ac72013-01-16 17:02:20 -0700911 .read_resources = nb_read_resources,
912 .set_resources = nb_set_resources,
Marc Jones8d595692012-03-15 12:55:26 -0600913 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenko4ab588b2014-10-08 21:18:31 +0200914 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
915 .write_acpi_tables = agesa_write_acpi_tables,
Marc Jones8d595692012-03-15 12:55:26 -0600916 .init = northbridge_init,
917 .enable = 0,.ops_pci = 0,
Frank Vibrans39fca802011-02-14 18:35:15 +0000918};
919
Frank Vibrans39fca802011-02-14 18:35:15 +0000920static const struct pci_driver northbridge_driver __pci_driver = {
Marc Jones8d595692012-03-15 12:55:26 -0600921 .ops = &northbridge_operations,
922 .vendor = PCI_VENDOR_ID_AMD,
923 .device = 0x1510,
Frank Vibrans39fca802011-02-14 18:35:15 +0000924};
925
efdesign9805a89ab2011-06-20 17:38:49 -0700926struct chip_operations northbridge_amd_agesa_family14_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600927 CHIP_NAME("AMD Family 14h Northbridge")
928 .enable_dev = 0,
Frank Vibrans39fca802011-02-14 18:35:15 +0000929};
930
Frank Vibrans39fca802011-02-14 18:35:15 +0000931/* Root Complex Structures */
932
Frank Vibrans39fca802011-02-14 18:35:15 +0000933static struct device_operations pci_domain_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600934 .read_resources = domain_read_resources,
935 .set_resources = domain_set_resources,
936 .enable_resources = domain_enable_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100937 .init = DEVICE_NOOP,
Marc Jones8d595692012-03-15 12:55:26 -0600938 .scan_bus = pci_domain_scan_bus,
Frank Vibrans39fca802011-02-14 18:35:15 +0000939};
940
Frank Vibrans39fca802011-02-14 18:35:15 +0000941static struct device_operations cpu_bus_ops = {
Edward O'Callaghan2837ab22014-11-06 08:57:40 +1100942 .read_resources = DEVICE_NOOP,
943 .set_resources = DEVICE_NOOP,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100944 .enable_resources = DEVICE_NOOP,
Marc Jones8d595692012-03-15 12:55:26 -0600945 .init = cpu_bus_init,
zbaof7223732012-04-13 13:42:15 +0800946 .scan_bus = cpu_bus_scan,
Frank Vibrans39fca802011-02-14 18:35:15 +0000947};
948
Kyösti Mälkki87213b62012-08-27 20:00:33 +0300949static void root_complex_enable_dev(struct device *dev)
950{
951 static int done = 0;
952
953 /* Do not delay UMA setup, as a device on the PCI bus may evaluate
954 the global uma_memory variables already in its enable function. */
955 if (!done) {
956 setup_bsp_ramtop();
957 setup_uma_memory();
958 done = 1;
959 }
960
Marc Jones8d595692012-03-15 12:55:26 -0600961 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800962 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Marc Jones8d595692012-03-15 12:55:26 -0600963 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800964 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Marc Jones8d595692012-03-15 12:55:26 -0600965 dev->ops = &cpu_bus_ops;
966 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000967}
968
efdesign9805a89ab2011-06-20 17:38:49 -0700969struct chip_operations northbridge_amd_agesa_family14_root_complex_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600970 CHIP_NAME("AMD Family 14h Root Complex")
971 .enable_dev = root_complex_enable_dev,
Frank Vibrans39fca802011-02-14 18:35:15 +0000972};