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