blob: 38d94a60d4174d14a63dc9b0120f9e3adc23f5a4 [file] [log] [blame]
Marc Jones738347e2010-09-13 19:24:38 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 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
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20//#define SYSTEM_TYPE 0 /* SERVER */
21#define SYSTEM_TYPE 1 /* DESKTOP */
22//#define SYSTEM_TYPE 2 /* MOBILE */
23
24#define RAMINIT_SYSINFO 1
25#define CACHE_AS_RAM_ADDRESS_DEBUG 1
26
27#define SET_NB_CFG_54 1
28
29//used by raminit
30#define QRANK_DIMM_SUPPORT 1
31
32//used by incoherent_ht
33#define FAM10_SCAN_PCI_BUS 0
34#define FAM10_ALLOCATE_IO_RANGE 0
35
36//used by init_cpus and fidvid
37#define SET_FIDVID 1
38#define SET_FIDVID_CORE_RANGE 0
39
40/* UART address and device number */
41#define SERIAL_DEV PNP_DEV(0x2e, F71859_SP1)
42
43#include <stdint.h>
44#include <string.h>
45#include <device/pci_def.h>
46#include <device/pci_ids.h>
47#include <arch/io.h>
48#include <device/pnp_def.h>
49#include <arch/romcc_io.h>
50#include <cpu/x86/lapic.h>
51#include <console/console.h>
52#include "lib/ramtest.c"
53#include <cpu/amd/model_10xxx_rev.h>
54#include "northbridge/amd/amdfam10/raminit.h"
55#include "northbridge/amd/amdfam10/amdfam10.h"
56
57#include "cpu/x86/lapic/boot_cpu.c"
58#include "northbridge/amd/amdfam10/reset_test.c"
59
60#include <console/loglevel.h>
61#include "cpu/x86/bist.h"
62
63static int smbus_read_byte(u32 device, u32 address);
64
65#include "superio/fintek/f71859/f71859_early_serial.c"
Uwe Hermannb015d022010-09-24 18:18:20 +000066
67#if CONFIG_USBDEBUG
68#include "southbridge/amd/sb700/sb700_enable_usbdebug.c"
69#include "pc80/usbdebug_serial.c"
70#endif
71
Marc Jones738347e2010-09-13 19:24:38 +000072#include "cpu/x86/mtrr/earlymtrr.c"
73#include <cpu/amd/mtrr.h>
74#include "northbridge/amd/amdfam10/setup_resource_map.c"
75
76#include "southbridge/amd/rs780/rs780_early_setup.c"
77#include "southbridge/amd/sb700/sb700_early_setup.c"
78#include "northbridge/amd/amdfam10/debug.c"
79
80static void activate_spd_rom(const struct mem_controller *ctrl)
81{
82}
83
84static int spd_read_byte(u32 device, u32 address)
85{
86 int result;
87 result = smbus_read_byte(device, address);
88 return result;
89}
90
91#include "northbridge/amd/amdfam10/amdfam10.h"
92
93#include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
94#include "northbridge/amd/amdfam10/amdfam10_pci.c"
95
96#include "resourcemap.c"
97#include "cpu/amd/quadcore/quadcore.c"
98
99#include "cpu/amd/car/post_cache_as_ram.c"
100#include "cpu/amd/microcode/microcode.c"
101#include "cpu/amd/model_10xxx/update_microcode.c"
102#include "cpu/amd/model_10xxx/init_cpus.c"
103
104#include "northbridge/amd/amdfam10/early_ht.c"
105#include "southbridge/amd/sb700/sb700_early_setup.c"
106
107//#include "spd_addr.h"
108
109#define RC00 0
110#define RC01 1
111
112#define DIMM0 0x50
113#define DIMM1 0x51
114#define DIMM2 0x52
115#define DIMM3 0x53
116
117void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
118{
119
120 struct sys_info *sysinfo = (struct sys_info *)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
121 static const u8 spd_addr[] = {RC00, DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0, };
122 u32 bsp_apicid = 0;
123 u32 val;
124 msr_t msr;
125
126 if (!cpu_init_detectedx && boot_cpu()) {
127 /* Nothing special needs to be done to find bus 0 */
128 /* Allow the HT devices to be found */
129 /* mov bsp to bus 0xff when > 8 nodes */
130 set_bsp_node_CHtExtNodeCfgEn();
131 enumerate_ht_chain();
132
133 sb700_pci_port80();
134 }
135
136 post_code(0x30);
137
138 if (bist == 0) {
139 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); /* mmconf is inited in init_cpus */
140 /* All cores run this but the BSP(node0,core0) is the only core that returns. */
141 }
142
143 post_code(0x32);
144
145 enable_rs780_dev8();
146 sb700_lpc_init();
147
148 f71859_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
149 uart_init();
Uwe Hermannb015d022010-09-24 18:18:20 +0000150
151#if CONFIG_USBDEBUG
152 sb700_enable_usbdebug(0);
153 early_usbdebug_init();
154#endif
155
Marc Jones738347e2010-09-13 19:24:38 +0000156 console_init();
157 printk(BIOS_DEBUG, "\n");
158
159// dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE);
160
161 /* Halt if there was a built in self test failure */
162 report_bist_failure(bist);
163
164 // Load MPB
165 val = cpuid_eax(1);
166 printk(BIOS_DEBUG, "BSP Family_Model: %08x \n", val);
167 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
168 printk(BIOS_DEBUG, "bsp_apicid = %02x \n", bsp_apicid);
169 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx \n", cpu_init_detectedx);
170
171 /* Setup sysinfo defaults */
172 set_sysinfo_in_ram(0);
173
174 update_microcode(val);
175 post_code(0x33);
176
177 cpuSetAMDMSR();
178 post_code(0x34);
179
180 amd_ht_init(sysinfo);
181 post_code(0x35);
182
183 /* Setup nodes PCI space and start core 0 AP init. */
184 finalize_node_setup(sysinfo);
185
186 /* Setup any mainboard PCI settings etc. */
187 setup_mb_resource_map();
188 post_code(0x36);
189
190 /* wait for all the APs core0 started by finalize_node_setup. */
191 /* FIXME: A bunch of cores are going to start output to serial at once.
192 It would be nice to fixup prink spinlocks for ROM XIP mode.
193 I think it could be done by putting the spinlock flag in the cache
194 of the BSP located right after sysinfo.
195 */
196 wait_all_core0_started();
197
198 #if CONFIG_LOGICAL_CPUS==1
199 /* Core0 on each node is configured. Now setup any additional cores. */
200 printk(BIOS_DEBUG, "start_other_cores()\n");
201 start_other_cores();
202 post_code(0x37);
203 wait_all_other_cores_started(bsp_apicid);
204 #endif
205
206 post_code(0x38);
207
208 /* run _early_setup before soft-reset. */
209 rs780_early_setup();
210 sb700_early_setup();
211
212 #if SET_FIDVID == 1
213 msr = rdmsr(0xc0010071);
214 printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x \n", msr.hi, msr.lo);
215
216 /* FIXME: The sb fid change may survive the warm reset and only
217 need to be done once.*/
218 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
219
220 post_code(0x39);
221
222 if (!warm_reset_detect(0)) { // BSP is node 0
223 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
224 } else {
225 init_fidvid_stage2(bsp_apicid, 0); // BSP is node 0
226 }
227
228 post_code(0x3A);
229
230 /* show final fid and vid */
231 msr=rdmsr(0xc0010071);
232 printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x \n", msr.hi, msr.lo);
233 #endif
234
235 rs780_htinit();
236
237 /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
238 if (!warm_reset_detect(0)) {
239 print_info("...WARM RESET...\n\n\n");
240 soft_reset();
241 die("After soft_reset_x - shouldn't see this message!!!\n");
242 }
243
244 post_code(0x3B);
245
246 /* It's the time to set ctrl in sysinfo now; */
247 printk(BIOS_DEBUG, "fill_mem_ctrl()\n");
248 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
249
250 post_code(0x40);
251
252// die("Die Before MCT init.");
253
254 printk(BIOS_DEBUG, "raminit_amdmct()\n");
255 raminit_amdmct(sysinfo);
256 post_code(0x41);
257
258/*
259 dump_pci_device_range(PCI_DEV(0, 0x18, 0), 0, 0x200);
260 dump_pci_device_range(PCI_DEV(0, 0x18, 1), 0, 0x200);
261 dump_pci_device_range(PCI_DEV(0, 0x18, 2), 0, 0x200);
262 dump_pci_device_range(PCI_DEV(0, 0x18, 3), 0, 0x200);
263*/
264
265// ram_check(0x00200000, 0x00200000 + (640 * 1024));
266// ram_check(0x40200000, 0x40200000 + (640 * 1024));
267
268// die("After MCT init before CAR disabled.");
269
270 rs780_before_pci_init();
271 sb700_before_pci_init();
272
273 post_code(0x42);
274 printk(BIOS_DEBUG, "\n*** Yes, the copy/decompress is taking a while, FIXME!\n");
275 post_cache_as_ram(); // BSP switch stack to ram, copy then execute LB.
276 post_code(0x43); // Should never see this post code.
277}
278