blob: d440f4d2f92bb6c3aa23805fbdab42c01437de03 [file] [log] [blame]
Maggie Li19ead962008-12-09 21:52:42 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008 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 ASSEMBLY 1
Myles Watson1d6d45e2009-11-06 17:02:51 +000021#define __PRE_RAM__
Maggie Li19ead962008-12-09 21:52:42 +000022
23#define RAMINIT_SYSINFO 1
24#define K8_SET_FIDVID 1
25#define QRANK_DIMM_SUPPORT 1
26#if CONFIG_LOGICAL_CPUS==1
27#define SET_NB_CFG_54 1
28#endif
29
30#define DIMM0 0x50
31#define DIMM1 0x51
32
33#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000034#include <string.h>
Maggie Li19ead962008-12-09 21:52:42 +000035#include <device/pci_def.h>
36#include <arch/io.h>
37#include <device/pnp_def.h>
38#include <arch/romcc_io.h>
39#include <cpu/x86/lapic.h>
40#include "option_table.h"
41#include "pc80/mc146818rtc_early.c"
42#include "pc80/serial.c"
43#include "arch/i386/lib/console.c"
44
45#define post_code(x) outb(x, 0x80)
46
47#include <cpu/amd/model_fxx_rev.h>
48#include "northbridge/amd/amdk8/raminit.h"
49#include "cpu/amd/model_fxx/apic_timer.c"
50#include "lib/delay.c"
51
Maggie Li19ead962008-12-09 21:52:42 +000052#include "cpu/x86/lapic/boot_cpu.c"
53#include "northbridge/amd/amdk8/reset_test.c"
Maggie Li19ead962008-12-09 21:52:42 +000054#include "superio/ite/it8712f/it8712f_early_serial.c"
55
56#include "cpu/amd/mtrr/amd_earlymtrr.c"
57#include "cpu/x86/bist.h"
58
59#include "northbridge/amd/amdk8/setup_resource_map.c"
60
61#include "southbridge/amd/rs690/rs690_early_setup.c"
62#include "southbridge/amd/sb600/sb600_early_setup.c"
Uwe Hermann01ce6012010-03-05 10:03:50 +000063#include "northbridge/amd/amdk8/debug.c" /* After sb600_early_setup.c! */
Maggie Li19ead962008-12-09 21:52:42 +000064
65/* CAN'T BE REMOVED! crt0.S will use it. I don't know WHY!*/
66static void memreset(int controllers, const struct mem_controller *ctrl)
67{
68}
69
70/* called in raminit_f.c */
71static inline void activate_spd_rom(const struct mem_controller *ctrl)
72{
73}
74
75/*called in raminit_f.c */
76static inline int spd_read_byte(u32 device, u32 address)
77{
78 return smbus_read_byte(device, address);
79}
80
81#include "northbridge/amd/amdk8/amdk8.h"
82#include "northbridge/amd/amdk8/incoherent_ht.c"
Myles Watson17257032009-06-04 20:18:42 +000083#include "northbridge/amd/amdk8/raminit_f.c"
Maggie Li19ead962008-12-09 21:52:42 +000084#include "northbridge/amd/amdk8/coherent_ht.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000085#include "lib/generic_sdram.c"
Maggie Li19ead962008-12-09 21:52:42 +000086#include "resourcemap.c"
87
88#include "cpu/amd/dualcore/dualcore.c"
89
90#include "cpu/amd/car/copy_and_run.c"
91#include "cpu/amd/car/post_cache_as_ram.c"
92
93#include "cpu/amd/model_fxx/init_cpus.c"
94
95#include "cpu/amd/model_fxx/fidvid.c"
96
Stefan Reinauer08670622009-06-30 15:17:49 +000097#if CONFIG_USE_FALLBACK_IMAGE == 1
Maggie Li19ead962008-12-09 21:52:42 +000098
99#include "northbridge/amd/amdk8/early_ht.c"
100
101void failover_process(unsigned long bist, unsigned long cpu_init_detectedx)
102{
103 /* Is this a cpu only reset? Is this a secondary cpu? */
104 if ((cpu_init_detectedx) || (!boot_cpu())) {
105 if (last_boot_normal()) { /* RTC already inited */
106 goto normal_image;
107 } else {
108 goto fallback_image;
109 }
110 }
111 /* Nothing special needs to be done to find bus 0 */
112 /* Allow the HT devices to be found */
113 enumerate_ht_chain();
114
115 sb600_lpc_port80();
116 /* sb600_pci_port80(); */
117
118 /* Is this a deliberate reset by the bios */
119 if (bios_reset_detected() && last_boot_normal()) {
120 goto normal_image;
121 }
122 /* This is the primary cpu how should I boot? */
123 else if (do_normal_boot()) {
124 goto normal_image;
125 } else {
126 goto fallback_image;
127 }
128 normal_image:
129 post_code(0x01);
130 __asm__ volatile ("jmp __normal_image": /* outputs */
131 :"a" (bist), "b"(cpu_init_detectedx)); /* inputs */
132
133 fallback_image:
134 post_code(0x02);
135}
Stefan Reinauer08670622009-06-30 15:17:49 +0000136#endif /* CONFIG_USE_FALLBACK_IMAGE == 1 */
Maggie Li19ead962008-12-09 21:52:42 +0000137
138void real_main(unsigned long bist, unsigned long cpu_init_detectedx);
139
140void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
141{
142
Stefan Reinauer08670622009-06-30 15:17:49 +0000143#if CONFIG_USE_FALLBACK_IMAGE == 1
Maggie Li19ead962008-12-09 21:52:42 +0000144 failover_process(bist, cpu_init_detectedx);
145#endif
146 real_main(bist, cpu_init_detectedx);
147}
148
149void real_main(unsigned long bist, unsigned long cpu_init_detectedx)
150{
151 static const u16 spd_addr[] = { DIMM0, 0, 0, 0, DIMM1, 0, 0, 0, };
152 int needs_reset = 0;
153 u32 bsp_apicid = 0;
154 msr_t msr;
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000155 struct cpuid_result cpuid1;
Maggie Li19ead962008-12-09 21:52:42 +0000156 struct sys_info *sysinfo =
Stefan Reinauer08670622009-06-30 15:17:49 +0000157 (struct sys_info *)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE -
158 CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
Maggie Li19ead962008-12-09 21:52:42 +0000159
160 if (bist == 0) {
161 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
162 }
163
164 enable_rs690_dev8();
165 sb600_lpc_init();
166
167 /* Pistachio used a FPGA to enable serial debug instead of a SIO
168 * and it doens't require any special setup. */
169 uart_init();
170 console_init();
171
172 post_code(0x03);
173
174 /* Halt if there was a built in self test failure */
175 report_bist_failure(bist);
176 printk_debug("bsp_apicid=0x%x\n", bsp_apicid);
177
178 setup_pistachio_resource_map();
179
180 setup_coherent_ht_domain();
181
182#if CONFIG_LOGICAL_CPUS==1
183 /* It is said that we should start core1 after all core0 launched */
184 wait_all_core0_started();
185 start_other_cores();
186#endif
187 wait_all_aps_started(bsp_apicid);
188
189 /* it will set up chains and store link pair for optimization later,
190 * it will init sblnk and sbbusn, nodes, sbdn */
191 ht_setup_chains_x(sysinfo);
192
193 /* run _early_setup before soft-reset. */
194 rs690_early_setup();
195 sb600_early_setup();
196
197 post_code(0x04);
198
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000199 /* Check to see if processor is capable of changing FIDVID */
200 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
201 cpuid1 = cpuid(0x80000007);
202 if( (cpuid1.edx & 0x6) == 0x6 ) {
Maggie Li19ead962008-12-09 21:52:42 +0000203
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000204 /* Read FIDVID_STATUS */
205 msr=rdmsr(0xc0010042);
206 printk_debug("begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
Maggie Li19ead962008-12-09 21:52:42 +0000207
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000208 enable_fid_change();
209 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
210 init_fidvid_bsp(bsp_apicid);
211
212 /* show final fid and vid */
213 msr=rdmsr(0xc0010042);
214 printk_debug("end msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
215
216 } else {
217 printk_debug("Changing FIDVID not supported\n");
218 }
Maggie Li19ead962008-12-09 21:52:42 +0000219
220 post_code(0x05);
221
222 needs_reset = optimize_link_coherent_ht();
223 needs_reset |= optimize_link_incoherent_ht(sysinfo);
Carl-Daniel Hailfinger33f96332008-12-23 17:20:46 +0000224 rs690_htinit();
Maggie Li19ead962008-12-09 21:52:42 +0000225 printk_debug("needs_reset=0x%x\n", needs_reset);
226
227 post_code(0x06);
228
229 if (needs_reset) {
230 print_info("ht reset -\r\n");
231 soft_reset();
232 }
233
234 allow_all_aps_stop(bsp_apicid);
235
236 /* It's the time to set ctrl now; */
237 printk_debug("sysinfo->nodes: %2x sysinfo->ctrl: %2x spd_addr: %2x\n",
238 sysinfo->nodes, sysinfo->ctrl, spd_addr);
239 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
240
241 post_code(0x07);
242
243 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
244
245 post_code(0x08);
246
247 rs690_before_pci_init();
248 sb600_before_pci_init();
249
250 post_cache_as_ram();
251}