This patch is from 2009-10-20
[coreboot.git] / src / mainboard / asus / a8n_e / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 AMD
5  * (Written by Yinghai Lu <yinghailu@amd.com> for AMD)
6  * Copyright (C) 2007 Philipp Degler <pdegler@rumms.uni-mannheim.de>
7  * (Thanks to LSRA University of Mannheim for their support)
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22  */
23
24 #define ASSEMBLY 1
25 #define __PRE_RAM__
26
27 /* Used by it8712f_enable_serial(). */
28 #define SERIAL_DEV PNP_DEV(0x2e, IT8712F_SP1)
29
30 /* Used by raminit. */
31 #define QRANK_DIMM_SUPPORT 1
32
33 #if CONFIG_LOGICAL_CPUS == 1
34 #define SET_NB_CFG_54 1
35 #endif
36
37 #include <stdint.h>
38 #include <string.h>
39 #include <device/pci_def.h>
40 #include <arch/io.h>
41 #include <device/pnp_def.h>
42 #include <arch/romcc_io.h>
43 #include <cpu/x86/lapic.h>
44 #include "option_table.h"
45 #include "pc80/mc146818rtc_early.c"
46 #include "cpu/x86/lapic/boot_cpu.c"
47 #include "northbridge/amd/amdk8/reset_test.c"
48 #include "superio/ite/it8712f/it8712f_early_serial.c"
49
50 #if CONFIG_USE_FAILOVER_IMAGE == 0
51
52 /* Used by ck894_early_setup(). */
53 #define CK804_NUM 1
54
55 #include <cpu/amd/model_fxx_rev.h>
56 #include "pc80/serial.c"
57 #include "arch/i386/lib/console.c"
58 #include "lib/ramtest.c"
59 #include "northbridge/amd/amdk8/incoherent_ht.c"
60 #include "southbridge/nvidia/ck804/ck804_early_smbus.c"
61 #include "northbridge/amd/amdk8/raminit.h"
62 #include "cpu/amd/model_fxx/apic_timer.c"
63 #include "lib/delay.c"
64 #include "northbridge/amd/amdk8/debug.c"
65 #include "cpu/amd/mtrr/amd_earlymtrr.c"
66 #include "cpu/x86/bist.h"
67 #include "northbridge/amd/amdk8/setup_resource_map.c"
68 #include "northbridge/amd/amdk8/coherent_ht.c"
69 #include "cpu/amd/dualcore/dualcore.c"
70
71 static void memreset_setup(void)
72 {
73         /* Nothing to do. */
74 }
75
76 static void memreset(int controllers, const struct mem_controller *ctrl)
77 {
78         /* Nothing to do. */
79 }
80
81 static inline void activate_spd_rom(const struct mem_controller *ctrl)
82 {
83         /* Nothing to do. */
84 }
85
86 static inline int spd_read_byte(unsigned device, unsigned address)
87 {
88         return smbus_read_byte(device, address);
89 }
90
91 #include "northbridge/amd/amdk8/raminit.c"
92 #include "lib/generic_sdram.c"
93 #include "southbridge/nvidia/ck804/ck804_early_setup_ss.h"
94 #include "southbridge/nvidia/ck804/ck804_early_setup.c"
95 #include "cpu/amd/car/copy_and_run.c"
96 #include "cpu/amd/car/post_cache_as_ram.c"
97 #include "cpu/amd/model_fxx/init_cpus.c"
98
99 #endif  /* CONFIG_USE_FAILOVER_IMAGE */
100
101 #if ((CONFIG_HAVE_FAILOVER_BOOT==1) && (CONFIG_USE_FAILOVER_IMAGE == 1)) \
102         || ((CONFIG_HAVE_FAILOVER_BOOT==0) && (CONFIG_USE_FALLBACK_IMAGE == 1))
103
104 #include "southbridge/nvidia/ck804/ck804_enable_rom.c"
105 #include "northbridge/amd/amdk8/early_ht.c"
106
107 static void sio_setup(void)
108 {
109         unsigned value;
110         uint32_t dword;
111         uint8_t byte;
112
113         /* Subject decoding */
114         byte = pci_read_config8(PCI_DEV(0, CK804_DEVN_BASE + 1, 0), 0x7b);
115         byte |= 0x20;
116         pci_write_config8(PCI_DEV(0, CK804_DEVN_BASE + 1, 0), 0x7b, byte);
117
118         /* LPC Positive Decode 0 */
119         dword = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE + 1, 0), 0xa0);
120         dword |= (1 << 0) | (1 << 1);   /* Serial 0, Serial 1 */
121         pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE + 1, 0), 0xa0, dword);
122 }
123
124 void failover_process(unsigned long bist, unsigned long cpu_init_detectedx)
125 {
126         unsigned last_boot_normal_x = last_boot_normal();
127
128         /* Is this a CPU only reset? Or is this a secondary CPU? */
129         if ((cpu_init_detectedx) || (!boot_cpu())) {
130                 if (last_boot_normal_x) {
131                         goto normal_image;
132                 } else {
133                         goto fallback_image;
134                 }
135         }
136
137         /* Nothing special needs to be done to find bus 0 */
138         /* Allow the HT devices to be found */
139         enumerate_ht_chain();
140
141         sio_setup();
142
143         /* Setup the ck804 */
144         ck804_enable_rom();
145
146         /* Is this a deliberate reset by the BIOS? */
147         if (bios_reset_detected() && last_boot_normal_x) {
148                 goto normal_image;
149         }
150
151         /* This is the primary CPU. How should I boot? */
152         else if (do_normal_boot()) {
153                 goto normal_image;
154         } else {
155                 goto fallback_image;
156         }
157
158 normal_image:
159         __asm__ volatile ("jmp __normal_image"
160                 :                                       /* outputs */
161                 :"a" (bist), "b"(cpu_init_detectedx)    /* inputs */
162                 );
163
164 fallback_image:
165
166 #if CONFIG_HAVE_FAILOVER_BOOT == 1
167         __asm__ volatile ("jmp __fallback_image"
168                 :                                       /* outputs */
169                 :"a" (bist), "b"(cpu_init_detectedx)    /* inputs */
170                 )
171 #endif
172         ;
173 }
174
175 #endif /* ((CONFIG_HAVE_FAILOVER_BOOT==1) && (CONFIG_USE_FAILOVER_IMAGE == 1)) ... */
176
177 void real_main(unsigned long bist, unsigned long cpu_init_detectedx);
178
179 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
180 {
181 #if CONFIG_HAVE_FAILOVER_BOOT == 1
182 #if CONFIG_USE_FAILOVER_IMAGE == 1
183         failover_process(bist, cpu_init_detectedx);
184 #else
185         real_main(bist, cpu_init_detectedx);
186 #endif
187 #else
188 #if CONFIG_USE_FALLBACK_IMAGE == 1
189         failover_process(bist, cpu_init_detectedx);
190 #endif
191         real_main(bist, cpu_init_detectedx);
192 #endif
193 }
194
195 #if CONFIG_USE_FAILOVER_IMAGE == 0
196 void real_main(unsigned long bist, unsigned long cpu_init_detectedx)
197 {
198         static const uint16_t spd_addr[] = {
199                 (0xa << 3) | 0, (0xa << 3) | 2, 0, 0,
200                 (0xa << 3) | 1, (0xa << 3) | 3, 0, 0,
201 #if CONFIG_MAX_PHYSICAL_CPUS > 1
202                 (0xa << 3) | 4, (0xa << 3) | 6, 0, 0,
203                 (0xa << 3) | 5, (0xa << 3) | 7, 0, 0,
204 #endif
205         };
206
207         int needs_reset;
208         unsigned nodes, bsp_apicid = 0;
209         struct mem_controller ctrl[8];
210
211         if (bist == 0)
212                 bsp_apicid = init_cpus(cpu_init_detectedx);
213
214         it8712f_24mhz_clkin();
215         it8712f_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
216         uart_init();
217         console_init();
218
219         /* Halt if there was a built in self test failure */
220         report_bist_failure(bist);
221
222 #if 0
223         dump_pci_device(PCI_DEV(0, 0x18, 0));
224 #endif
225
226         needs_reset = setup_coherent_ht_domain();
227
228         wait_all_core0_started();
229 #if CONFIG_LOGICAL_CPUS==1
230         /* It is said that we should start core1 after all core0 launched. */
231         start_other_cores();
232         wait_all_other_cores_started(bsp_apicid);
233 #endif
234
235         needs_reset |= ht_setup_chains_x();
236         needs_reset |= ck804_early_setup_x();
237
238         if (needs_reset) {
239                 print_info("ht reset -\r\n");
240                 soft_reset();
241         }
242
243         allow_all_aps_stop(bsp_apicid);
244
245         nodes = get_nodes();
246         /* It's the time to set ctrl now. */
247         fill_mem_ctrl(nodes, ctrl, spd_addr);
248
249         enable_smbus();
250
251 #if 0
252         dump_spd_registers(&ctrl[0]);
253         dump_smbus_registers();
254 #endif
255
256         memreset_setup();
257         sdram_initialize(nodes, ctrl);
258
259 #if 0
260         print_pci_devices();
261         dump_pci_devices();
262 #endif
263
264         post_cache_as_ram();
265 }
266 #endif /* CONFIG_USE_FAILOVER_IMAGE */