blob: 41c151e4237162d5043e55c09d3cfaa0c7dbe093 [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
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28#define RAMINIT_SYSINFO 1
29
30#define FAM10_SCAN_PCI_BUS 0
31#define FAM10_ALLOCATE_IO_RANGE 1
32
33#define QRANK_DIMM_SUPPORT 1
34
35#if CONFIG_LOGICAL_CPUS==1
36#define SET_NB_CFG_54 1
37#endif
38
39#define SET_FIDVID 1
40#define SET_FIDVID_CORE_RANGE 0
41
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000042#include <stdint.h>
43#include <string.h>
44#include <device/pci_def.h>
45#include <device/pci_ids.h>
46#include <arch/io.h>
47#include <device/pnp_def.h>
48#include <arch/romcc_io.h>
49#include <cpu/x86/lapic.h>
50#include "option_table.h"
51#include <console/console.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000052#include <cpu/amd/model_10xxx_rev.h>
53#include "southbridge/broadcom/bcm5785/bcm5785_early_smbus.c"
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000054#include "northbridge/amd/amdfam10/raminit.h"
55#include "northbridge/amd/amdfam10/amdfam10.h"
Patrick Georgid0835952010-10-05 09:07:10 +000056#include <lib.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000057
58#include "cpu/amd/model_10xxx/apic_timer.c"
59#include "lib/delay.c"
60#include "cpu/x86/lapic/boot_cpu.c"
61#include "northbridge/amd/amdfam10/reset_test.c"
62
63#include "superio/serverengines/pilot/pilot_early_serial.c"
64#include "superio/serverengines/pilot/pilot_early_init.c"
65#include "superio/nsc/pc87417/pc87417_early_serial.c"
66
67#include "cpu/x86/bist.h"
68
69#include "northbridge/amd/amdfam10/debug.c"
70
71#include "cpu/x86/mtrr/earlymtrr.c"
72
73//#include "northbridge/amd/amdfam10/setup_resource_map.c"
74
75#define SERIAL_DEV PNP_DEV(0x2e, PILOT_SP1)
76#define RTC_DEV PNP_DEV(0x4e, PC87417_RTC)
77
78#include "southbridge/broadcom/bcm5785/bcm5785_early_setup.c"
79
80static inline void activate_spd_rom(const struct mem_controller *ctrl)
81{
82 u8 val;
83 outb(0x3d, 0x0cd6);
84 outb(0x87, 0x0cd7);
85
86 outb(0x44, 0xcd6);
87 val = inb(0xcd7);
88 outb((val & ~3) | ctrl->spd_switch_addr, 0xcd7);
89}
90
91static inline int spd_read_byte(unsigned device, unsigned address)
92{
93 return smbus_read_byte(device, address);
94}
95
96#include "northbridge/amd/amdfam10/amdfam10.h"
97
98#include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
99#include "northbridge/amd/amdfam10/amdfam10_pci.c"
100
101#include "cpu/amd/quadcore/quadcore.c"
102
103#include "cpu/amd/car/post_cache_as_ram.c"
104
105#include "cpu/amd/microcode/microcode.c"
106#include "cpu/amd/model_10xxx/update_microcode.c"
107#include "cpu/amd/model_10xxx/init_cpus.c"
108
109#include "northbridge/amd/amdfam10/early_ht.c"
110
111#include "spd_addr.h"
112
113void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
114{
115 struct sys_info *sysinfo = (struct sys_info *)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
116
117
118 u32 bsp_apicid = 0;
119 u32 val;
120 msr_t msr;
121
122 if (!cpu_init_detectedx && boot_cpu()) {
123 /* Nothing special needs to be done to find bus 0 */
124 /* Allow the HT devices to be found */
125 /* mov bsp to bus 0xff when > 8 nodes */
126 set_bsp_node_CHtExtNodeCfgEn();
127 enumerate_ht_chain();
128
129 /* Setup the rom access for 4M */
130 bcm5785_enable_rom();
131 bcm5785_enable_lpc();
132 //enable RTC
133 pc87417_enable_dev(RTC_DEV);
134 }
135
136 post_code(0x30);
137
138 if (bist == 0) {
139 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
140 }
141
142 pilot_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
143
144 uart_init();
145
146 /* Halt if there was a built in self test failure */
147 report_bist_failure(bist);
148
149 console_init();
150 pilot_early_init(SERIAL_DEV); //config port is being taken from SERIAL_DEV
151
152 val = cpuid_eax(1);
153 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
154 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
155 printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
156 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
157
158 /* Setup sysinfo defaults */
159 set_sysinfo_in_ram(0);
160
161 update_microcode(val);
162 post_code(0x33);
163
164 cpuSetAMDMSR();
165 post_code(0x34);
166
167 amd_ht_init(sysinfo);
168 post_code(0x35);
169
170 /* Setup nodes PCI space and start core 0 AP init. */
171 finalize_node_setup(sysinfo);
172
173 post_code(0x36);
174
175 /* wait for all the APs core0 started by finalize_node_setup. */
176 /* FIXME: A bunch of cores are going to start output to serial at once.
177 * It would be nice to fixup prink spinlocks for ROM XIP mode.
178 * I think it could be done by putting the spinlock flag in the cache
179 * of the BSP located right after sysinfo.
180 */
181
182 wait_all_core0_started();
183
184#if CONFIG_LOGICAL_CPUS==1
185 /* Core0 on each node is configured. Now setup any additional cores. */
186 printk(BIOS_DEBUG, "start_other_cores()\n");
187 start_other_cores();
188 post_code(0x37);
189 wait_all_other_cores_started(bsp_apicid);
190#endif
191
192#if SET_FIDVID == 1
193 msr = rdmsr(0xc0010071);
194 printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
195
196 /* FIXME: The sb fid change may survive the warm reset and only
197 * need to be done once.*/
198
199 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
200
201 post_code(0x39);
202
203 if (!warm_reset_detect(0)) { // BSP is node 0
204 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
205 } else {
206 init_fidvid_stage2(bsp_apicid, 0); // BSP is node 0
207 }
208
209 post_code(0x3A);
210
211 /* show final fid and vid */
212 msr=rdmsr(0xc0010071);
213 printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
214#endif
215
216 init_timer();
217
218 /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
219 if (!warm_reset_detect(0)) {
220 print_info("...WARM RESET...\n\n\n");
221 soft_reset();
222 die("After soft_reset_x - shouldn't see this message!!!\n");
223 }
224
225 /* It's the time to set ctrl in sysinfo now; */
226 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
227 enable_smbus();
228
229 //do we need apci timer, tsc...., only debug need it for better output
230 /* all ap stopped? */
231// init_timer(); // Need to use TMICT to synconize FID/VID
232
233 printk(BIOS_DEBUG, "raminit_amdmct()\n");
234 raminit_amdmct(sysinfo);
235 post_code(0x41);
236
237 bcm5785_early_setup();
238
239 post_cache_as_ram();
240}