Please bear with me - another rename checkin. This qualifies as trivial, no
[coreboot.git] / src / mainboard / msi / ms7260 / cache_as_ram_auto.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 Uwe Hermann <uwe@hermann-uwe.de>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21  */
22
23 #define ASSEMBLY 1
24 #define __ROMCC__
25
26 // #define CACHE_AS_RAM_ADDRESS_DEBUG 1
27 // #define DEBUG_SMBUS 1
28 // #define RAM_TIMING_DEBUG 1
29 // #define DQS_TRAIN_DEBUG 1
30 // #define RES_DEBUG 1
31
32 #define RAMINIT_SYSINFO 1
33 #define K8_ALLOCATE_IO_RANGE 1
34 // #define K8_SCAN_PCI_BUS 1            /* ? */
35 #define QRANK_DIMM_SUPPORT 1
36 #if CONFIG_LOGICAL_CPUS == 1
37 #define SET_NB_CFG_54 1
38 #endif
39
40 /* Used by init_cpus and fidvid. */
41 #define K8_SET_FIDVID 1
42
43 /* If we want to wait for core1 done before DQS training, set it to 0. */
44 #define K8_SET_FIDVID_CORE0_ONLY 1
45
46 #if K8_REV_F_SUPPORT == 1
47 #define K8_REV_F_SUPPORT_F0_F1_WORKAROUND 0
48 #endif
49
50 #define DBGP_DEFAULT 7
51
52 #include <stdint.h>
53 #include <device/pci_def.h>
54 #include <device/pci_ids.h>
55 #include <arch/io.h>
56 #include <device/pnp_def.h>
57 #include <arch/romcc_io.h>
58 #include <cpu/x86/lapic.h>
59 #include "option_table.h"
60 #include "pc80/mc146818rtc_early.c"
61
62 #if USE_FAILOVER_IMAGE == 0
63
64 #include "pc80/serial.c"
65 #include "arch/i386/lib/console.c"
66 #if CONFIG_USBDEBUG_DIRECT
67 #include "southbridge/nvidia/mcp55/mcp55_enable_usbdebug_direct.c"
68 #include "pc80/usbdebug_direct_serial.c"
69 #endif
70 #include "ram/ramtest.c"
71 #include <cpu/amd/model_fxx_rev.h>
72 #include "southbridge/nvidia/mcp55/mcp55_early_smbus.c"
73 #include "northbridge/amd/amdk8/raminit.h"
74 #include "cpu/amd/model_fxx/apic_timer.c"
75 #include "lib/delay.c"
76
77 #endif
78
79 #include "cpu/x86/lapic/boot_cpu.c"
80 #include "northbridge/amd/amdk8/reset_test.c"
81 #include "superio/winbond/w83627ehg/w83627ehg_early_serial.c"
82 #include "superio/winbond/w83627ehg/w83627ehg_early_init.c"
83
84 #if USE_FAILOVER_IMAGE == 0
85
86 #include "cpu/x86/bist.h"
87 #if CONFIG_USE_INIT == 0
88 #include "lib/memcpy.c"
89 #endif
90 #include "northbridge/amd/amdk8/debug.c"
91 #include "cpu/amd/mtrr/amd_earlymtrr.c"
92 #include "northbridge/amd/amdk8/setup_resource_map.c"
93
94 /* Yes, on the MSI K9N Neo (MS-7260) the Super I/O is at 0x4e! */
95 #define SERIAL_DEV PNP_DEV(0x4e, W83627EHG_SP1)
96
97 #include "southbridge/nvidia/mcp55/mcp55_early_ctrl.c"
98
99 static void memreset_setup(void) {}
100 static void memreset(int controllers, const struct mem_controller *ctrl) {}
101 static inline void activate_spd_rom(const struct mem_controller *ctrl) {}
102
103 static inline int spd_read_byte(unsigned int device, unsigned int address)
104 {
105         return smbus_read_byte(device, address);
106 }
107
108 #include "northbridge/amd/amdk8/amdk8_f.h"
109 #include "northbridge/amd/amdk8/coherent_ht.c"
110 #include "northbridge/amd/amdk8/incoherent_ht.c"
111 #include "northbridge/amd/amdk8/raminit_f.c"
112 #include "sdram/generic_sdram.c"
113 #include "resourcemap.c"
114 #include "cpu/amd/dualcore/dualcore.c"
115
116 #define MCP55_NUM 1
117 #define MCP55_USE_NIC 1
118 #define MCP55_USE_AZA 1
119 #define MCP55_PCI_E_X_0 0
120
121 #define MCP55_MB_SETUP \
122         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+37, 0x00, 0x44,/* GPIO38 PCI_REQ3 */ \
123         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+38, 0x00, 0x44,/* GPIO39 PCI_GNT3 */ \
124         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+39, 0x00, 0x44,/* GPIO40 PCI_GNT2 */ \
125         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+40, 0x00, 0x44,/* GPIO41 PCI_REQ2 */ \
126         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+59, 0x00, 0x60,/* GPIP60 FANCTL0 */ \
127         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+60, 0x00, 0x60,/* GPIO61 FANCTL1 */
128
129 #include "southbridge/nvidia/mcp55/mcp55_early_setup_ss.h"
130 #include "southbridge/nvidia/mcp55/mcp55_early_setup_car.c"
131 #include "cpu/amd/car/copy_and_run.c"
132 #include "cpu/amd/car/post_cache_as_ram.c"
133 #include "cpu/amd/model_fxx/init_cpus.c"
134 #include "cpu/amd/model_fxx/fidvid.c"
135
136 #endif
137
138 #if ((HAVE_FAILOVER_BOOT==1) && (USE_FAILOVER_IMAGE == 1)) || ((HAVE_FAILOVER_BOOT==0) && (USE_FALLBACK_IMAGE == 1))
139
140 #include "southbridge/nvidia/mcp55/mcp55_enable_rom.c"
141 #include "northbridge/amd/amdk8/early_ht.c"
142
143 static void sio_setup(void)
144 {
145         uint32_t dword;
146         uint8_t byte;
147
148         byte = pci_read_config8(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0x7b);
149         byte |= 0x20;
150         pci_write_config8(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0x7b, byte);
151
152         dword = pci_read_config32(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0xa0);
153         dword |= (1 << 0);
154         pci_write_config32(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0xa0, dword);
155
156         dword = pci_read_config32(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0xa4);
157         dword |= (1 << 16);
158         pci_write_config32(PCI_DEV(0, MCP55_DEVN_BASE + 1, 0), 0xa4, dword);
159 }
160
161 void failover_process(unsigned long bist, unsigned long cpu_init_detectedx)
162 {
163         unsigned int last_boot_normal_x = last_boot_normal();
164
165         /* Is this a CPU only reset? Or is this a secondary CPU? */
166         if ((cpu_init_detectedx) || (!boot_cpu())) {
167                 if (last_boot_normal_x)
168                         goto normal_image;
169                 else
170                         goto fallback_image;
171         }
172
173         /* Nothing special needs to be done to find bus 0. */
174         /* Allow the HT devices to be found. */
175         enumerate_ht_chain();
176
177         sio_setup();
178
179         /* Setup the MCP55. */
180         mcp55_enable_rom();
181
182         /* Is this a deliberate reset by the BIOS? */
183         if (bios_reset_detected() && last_boot_normal_x) {
184                 goto normal_image;
185         }
186         /* This is the primary CPU. How should I boot? */
187         else if (do_normal_boot()) {
188                 goto normal_image;
189         } else {
190                 goto fallback_image;
191         }
192
193 normal_image:
194         __asm__ volatile ("jmp __normal_image":
195                           :"a" (bist), "b"(cpu_init_detectedx)
196         );
197
198 fallback_image:
199 #if HAVE_FAILOVER_BOOT==1
200         __asm__ volatile ("jmp __fallback_image":
201                           :"a" (bist), "b"(cpu_init_detectedx)
202         )
203 #endif
204         ;
205 }
206 #endif
207
208 void real_main(unsigned long bist, unsigned long cpu_init_detectedx);
209
210 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
211 {
212 #if HAVE_FAILOVER_BOOT == 1
213 #if USE_FAILOVER_IMAGE == 1
214         failover_process(bist, cpu_init_detectedx);
215 #else
216         real_main(bist, cpu_init_detectedx);
217 #endif
218 #else
219 #if USE_FALLBACK_IMAGE == 1
220         failover_process(bist, cpu_init_detectedx);
221 #endif
222         real_main(bist, cpu_init_detectedx);
223 #endif
224 }
225
226 #if USE_FAILOVER_IMAGE == 0
227
228 void real_main(unsigned long bist, unsigned long cpu_init_detectedx)
229 {
230         static const uint16_t spd_addr[] = {
231                 (0xa << 3) | 0, (0xa << 3) | 2, 0, 0,
232                 (0xa << 3) | 1, (0xa << 3) | 3, 0, 0,
233 #if CONFIG_MAX_PHYSICAL_CPUS > 1
234                 (0xa << 3) | 4, (0xa << 3) | 6, 0, 0,
235                 (0xa << 3) | 5, (0xa << 3) | 7, 0, 0,
236 #endif
237         };
238
239         struct sys_info *sysinfo =
240             (DCACHE_RAM_BASE + DCACHE_RAM_SIZE - DCACHE_RAM_GLOBAL_VAR_SIZE);
241         int needs_reset = 0;
242         unsigned bsp_apicid = 0;
243
244         if (bist == 0)
245                 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
246
247         /* FIXME: This should be part of the Super I/O code/config. */
248         pnp_enter_ext_func_mode(SERIAL_DEV);
249         /* Switch CLKSEL to 24MHz (default is 48MHz). Needed for serial! */
250         pnp_write_config(SERIAL_DEV, 0x24, 0);
251         w83627ehg_enable_dev(SERIAL_DEV, TTYS0_BASE);
252         pnp_exit_ext_func_mode(SERIAL_DEV);
253
254         setup_mb_resource_map();
255         uart_init();
256         report_bist_failure(bist); /* Halt upon BIST failure. */
257 #if CONFIG_USBDEBUG_DIRECT
258         mcp55_enable_usbdebug_direct(DBGP_DEFAULT);
259         early_usbdebug_direct_init();
260 #endif
261         console_init();
262
263         print_debug("*sysinfo range: [");
264         print_debug_hex32(sysinfo);
265         print_debug(",");
266         print_debug_hex32((unsigned long)sysinfo + sizeof(struct sys_info));
267         print_debug(")\r\n");
268
269         print_debug("bsp_apicid=");
270         print_debug_hex8(bsp_apicid);
271         print_debug("\r\n");
272
273 #if MEM_TRAIN_SEQ == 1
274         /* In BSP so could hold all AP until sysinfo is in RAM. */
275         set_sysinfo_in_ram(0);
276 #endif
277
278         setup_coherent_ht_domain(); /* Routing table and start other core0. */
279         wait_all_core0_started();
280
281 #if CONFIG_LOGICAL_CPUS == 1
282         /* It is said that we should start core1 after all core0 launched
283          * becase optimize_link_coherent_ht is moved out from
284          * setup_coherent_ht_domain, so here need to make sure last core0 is
285          * started, esp for two way system (there may be APIC ID conflicts in
286          * that case).
287          */
288         start_other_cores();
289         wait_all_other_cores_started(bsp_apicid);
290 #endif
291
292         /* Set up chains and store link pair for optimization later. */
293         ht_setup_chains_x(sysinfo); /* Init sblnk and sbbusn, nodes, sbdn. */
294
295 #if K8_SET_FIDVID == 1
296         {
297                 msr_t msr = rdmsr(0xc0010042);
298                 print_debug("begin msr fid, vid ");
299                 print_debug_hex32(msr.hi);
300                 print_debug_hex32(msr.lo);
301                 print_debug("\r\n");
302         }
303
304         enable_fid_change();
305         enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
306         init_fidvid_bsp(bsp_apicid);
307
308         {
309                 msr_t msr = rdmsr(0xc0010042);
310                 print_debug("end   msr fid, vid ");
311                 print_debug_hex32(msr.hi);
312                 print_debug_hex32(msr.lo);
313                 print_debug("\r\n");
314         }
315 #endif
316
317         needs_reset |= optimize_link_coherent_ht();
318         needs_reset |= optimize_link_incoherent_ht(sysinfo);
319         needs_reset |= mcp55_early_setup_x();
320
321         /* fidvid change will issue one LDTSTOP and the HT change will be effective too. */
322         if (needs_reset) {
323                 print_info("ht reset -\r\n");
324                 soft_reset();
325         }
326         allow_all_aps_stop(bsp_apicid);
327
328         /* It's the time to set ctrl in sysinfo now. */
329         fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
330
331         enable_smbus();
332
333         memreset_setup();
334
335         /* Do we need apci timer, tsc...., only debug need it for better output */
336         /* All AP stopped? */
337         // init_timer(); /* Need to use TMICT to synconize FID/VID. */
338
339         sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
340
341         /* bsp switch stack to RAM and copy sysinfo RAM now. */
342         post_cache_as_ram();
343 }
344
345 #endif