blob: 474190b909d8f69d319f799eb25884ae2c8efef7 [file] [log] [blame]
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2006 Tyan
5 * Copyright (C) 2006 AMD
6 * Written by Yinghai Lu <yinghailu@gmail.com> for Tyan and AMD.
7 *
8 * Copyright (C) 2007 University of Mannheim
9 * Written by Philipp Degler <pdegler@rumms.uni-mannheim.de> for University of Mannheim
10 * Copyright (C) 2009 University of Heidelberg
11 * Written by Mondrian Nuessle <nuessle@uni-heidelberg.de> for University of Heidelberg
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010025 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000026 */
27
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000028#define FAM10_SCAN_PCI_BUS 0
29#define FAM10_ALLOCATE_IO_RANGE 1
30
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000031#include <stdint.h>
32#include <string.h>
33#include <device/pci_def.h>
34#include <device/pci_ids.h>
35#include <arch/io.h>
36#include <device/pnp_def.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000037#include <cpu/x86/lapic.h>
38#include "option_table.h"
39#include <console/console.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000040#include <cpu/amd/model_10xxx_rev.h>
stepan836ae292010-12-08 05:42:47 +000041#include "southbridge/broadcom/bcm5785/early_smbus.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000042#include "northbridge/amd/amdfam10/raminit.h"
43#include "northbridge/amd/amdfam10/amdfam10.h"
Patrick Georgid0835952010-10-05 09:07:10 +000044#include <lib.h>
Uwe Hermann26535d62010-11-20 20:36:40 +000045#include <spd.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000046#include "lib/delay.c"
Kyösti Mälkkic66f1cb2013-08-12 16:09:00 +030047#include "cpu/x86/lapic.h"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000048#include "northbridge/amd/amdfam10/reset_test.c"
Edward O'Callaghanf18abab2014-03-31 21:53:32 +110049#include <superio/serverengines/pilot/pilot.h>
stepan8301d832010-12-08 07:07:33 +000050#include "superio/nsc/pc87417/early_serial.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000051#include "cpu/x86/bist.h"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000052#include "northbridge/amd/amdfam10/debug.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000053//#include "northbridge/amd/amdfam10/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000054#include "southbridge/broadcom/bcm5785/early_setup.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000055
56#define SERIAL_DEV PNP_DEV(0x2e, PILOT_SP1)
57#define RTC_DEV PNP_DEV(0x4e, PC87417_RTC)
58
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000059static inline void activate_spd_rom(const struct mem_controller *ctrl)
60{
61 u8 val;
62 outb(0x3d, 0x0cd6);
63 outb(0x87, 0x0cd7);
64
65 outb(0x44, 0xcd6);
66 val = inb(0xcd7);
67 outb((val & ~3) | ctrl->spd_switch_addr, 0xcd7);
68}
69
70static inline int spd_read_byte(unsigned device, unsigned address)
71{
72 return smbus_read_byte(device, address);
73}
74
75#include "northbridge/amd/amdfam10/amdfam10.h"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000076#include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
stepan8301d832010-12-08 07:07:33 +000077#include "northbridge/amd/amdfam10/pci.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000078#include "cpu/amd/quadcore/quadcore.c"
Kyösti Mälkkif0a13ce2013-12-08 07:20:48 +020079#include "cpu/amd/microcode.h"
Xavi Drudis Ferran4c28a6f2011-02-26 23:29:44 +000080
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000081#include "cpu/amd/model_10xxx/init_cpus.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000082#include "northbridge/amd/amdfam10/early_ht.c"
83
Uwe Hermann26535d62010-11-20 20:36:40 +000084static const u8 spd_addr[] = {
85 // switch addr, 1A addr, 2A addr, 3A addr, 4A addr, 1B addr, 2B addr, 3B addr 4B addr
86 //first node
87 RC00, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0,
88#if CONFIG_MAX_PHYSICAL_CPUS > 1
89 //second node
90 RC01, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0,
91#endif
92};
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000093
94void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
95{
Patrick Georgibbc880e2012-11-20 18:20:56 +010096 struct sys_info *sysinfo = &sysinfo_car;
Uwe Hermann7b997052010-11-21 22:47:22 +000097 u32 bsp_apicid = 0, val;
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000098 msr_t msr;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070099
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000100 if (!cpu_init_detectedx && boot_cpu()) {
Uwe Hermann7b997052010-11-21 22:47:22 +0000101 /* Nothing special needs to be done to find bus 0 */
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000102 /* Allow the HT devices to be found */
103 /* mov bsp to bus 0xff when > 8 nodes */
104 set_bsp_node_CHtExtNodeCfgEn();
105 enumerate_ht_chain();
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000106 bcm5785_enable_lpc();
Uwe Hermann7b997052010-11-21 22:47:22 +0000107 pc87417_enable_dev(RTC_DEV); /* Enable RTC */
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000108 }
109
110 post_code(0x30);
111
Uwe Hermann7b997052010-11-21 22:47:22 +0000112 if (bist == 0)
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000113 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000114
115 pilot_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
116
Stefan Reinauer42fa7fe2011-04-20 20:54:07 +0000117 console_init();
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000118
119 /* Halt if there was a built in self test failure */
120 report_bist_failure(bist);
121
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000122 pilot_early_init(SERIAL_DEV); //config port is being taken from SERIAL_DEV
123
124 val = cpuid_eax(1);
125 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
126 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
127 printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
128 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
129
130 /* Setup sysinfo defaults */
131 set_sysinfo_in_ram(0);
132
133 update_microcode(val);
Kyösti Mälkkif0a13ce2013-12-08 07:20:48 +0200134
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000135 post_code(0x33);
136
137 cpuSetAMDMSR();
138 post_code(0x34);
139
140 amd_ht_init(sysinfo);
141 post_code(0x35);
142
143 /* Setup nodes PCI space and start core 0 AP init. */
144 finalize_node_setup(sysinfo);
145
146 post_code(0x36);
147
148 /* wait for all the APs core0 started by finalize_node_setup. */
149 /* FIXME: A bunch of cores are going to start output to serial at once.
150 * It would be nice to fixup prink spinlocks for ROM XIP mode.
151 * I think it could be done by putting the spinlock flag in the cache
152 * of the BSP located right after sysinfo.
153 */
154
155 wait_all_core0_started();
156
Patrick Georgie1667822012-05-05 15:29:32 +0200157#if CONFIG_LOGICAL_CPUS
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000158 /* Core0 on each node is configured. Now setup any additional cores. */
159 printk(BIOS_DEBUG, "start_other_cores()\n");
160 start_other_cores();
161 post_code(0x37);
162 wait_all_other_cores_started(bsp_apicid);
163#endif
164
Patrick Georgi76e81522010-11-16 21:25:29 +0000165#if CONFIG_SET_FIDVID
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000166 msr = rdmsr(0xc0010071);
167 printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
168
169 /* FIXME: The sb fid change may survive the warm reset and only
170 * need to be done once.*/
171
172 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
173
174 post_code(0x39);
175
176 if (!warm_reset_detect(0)) { // BSP is node 0
177 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
178 } else {
179 init_fidvid_stage2(bsp_apicid, 0); // BSP is node 0
180 }
181
182 post_code(0x3A);
183
184 /* show final fid and vid */
185 msr=rdmsr(0xc0010071);
186 printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
187#endif
188
189 init_timer();
190
191 /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
192 if (!warm_reset_detect(0)) {
193 print_info("...WARM RESET...\n\n\n");
194 soft_reset();
195 die("After soft_reset_x - shouldn't see this message!!!\n");
196 }
197
198 /* It's the time to set ctrl in sysinfo now; */
199 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
200 enable_smbus();
201
202 //do we need apci timer, tsc...., only debug need it for better output
203 /* all ap stopped? */
204// init_timer(); // Need to use TMICT to synconize FID/VID
205
206 printk(BIOS_DEBUG, "raminit_amdmct()\n");
207 raminit_amdmct(sysinfo);
208 post_code(0x41);
209
210 bcm5785_early_setup();
211
212 post_cache_as_ram();
213}
Scott Duplichan314dd0b2011-03-08 23:01:46 +0000214
215/**
216 * BOOL AMD_CB_ManualBUIDSwapList(u8 Node, u8 Link, u8 **List)
217 * Description:
218 * This routine is called every time a non-coherent chain is processed.
219 * BUID assignment may be controlled explicitly on a non-coherent chain. Provide a
220 * swap list. The first part of the list controls the BUID assignment and the
221 * second part of the list provides the device to device linking. Device orientation
222 * can be detected automatically, or explicitly. See documentation for more details.
223 *
224 * Automatic non-coherent init assigns BUIDs starting at 1 and incrementing sequentially
225 * based on each device's unit count.
226 *
227 * Parameters:
228 * @param[in] u8 node = The node on which this chain is located
229 * @param[in] u8 link = The link on the host for this chain
230 * @param[out] u8** list = supply a pointer to a list
231 * @param[out] BOOL result = true to use a manual list
232 * false to initialize the link automatically
233 */
234BOOL AMD_CB_ManualBUIDSwapList (u8 node, u8 link, const u8 **List)
235{
236 static const u8 swaplist[] = { 0xFF, CONFIG_HT_CHAIN_UNITID_BASE, CONFIG_HT_CHAIN_END_UNITID_BASE, 0xFF };
237 /* If the BUID was adjusted in early_ht we need to do the manual override */
238 if ((CONFIG_HT_CHAIN_UNITID_BASE != 0) && (CONFIG_HT_CHAIN_END_UNITID_BASE != 0)) {
239 printk(BIOS_DEBUG, "AMD_CB_ManualBUIDSwapList()\n");
240 if ((node == 0) && (link == 0)) { /* BSP SB link */
241 *List = swaplist;
242 return 1;
243 }
244 }
245
246 return 0;
247}