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