Re-integrate "USE_OPTION_TABLE" code.
[coreboot.git] / src / mainboard / tyan / s2912_fam10 / 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  *
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; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #define RAMINIT_SYSINFO 1
23
24 #define FAM10_SCAN_PCI_BUS 0
25 #define FAM10_ALLOCATE_IO_RANGE 1
26
27 #define QRANK_DIMM_SUPPORT 1
28
29 #if CONFIG_LOGICAL_CPUS==1
30 #define SET_NB_CFG_54 1
31 #endif
32
33 #define SET_FIDVID 1
34 #define SET_FIDVID_CORE_RANGE 0
35
36 #define DBGP_DEFAULT 7
37
38 #include <stdint.h>
39 #include <string.h>
40 #include <device/pci_def.h>
41 #include <device/pci_ids.h>
42 #include <arch/io.h>
43 #include <device/pnp_def.h>
44 #include <arch/romcc_io.h>
45 #include <cpu/x86/lapic.h>
46 #include <console/console.h>
47 #if CONFIG_USBDEBUG
48 #include "southbridge/nvidia/mcp55/mcp55_enable_usbdebug.c"
49 #include "pc80/usbdebug_serial.c"
50 #endif
51 #include "lib/ramtest.c"
52
53 #include <cpu/amd/model_10xxx_rev.h>
54
55 #include "southbridge/nvidia/mcp55/mcp55_early_smbus.c"
56 #include "northbridge/amd/amdfam10/raminit.h"
57 #include "northbridge/amd/amdfam10/amdfam10.h"
58
59 #include "cpu/amd/model_10xxx/apic_timer.c"
60 #include "lib/delay.c"
61 #include "cpu/x86/lapic/boot_cpu.c"
62 #include "northbridge/amd/amdfam10/reset_test.c"
63 #include "superio/winbond/w83627hf/w83627hf_early_serial.c"
64 #include "superio/winbond/w83627hf/w83627hf_early_init.c"
65
66 #include "cpu/x86/bist.h"
67
68 #include "northbridge/amd/amdfam10/debug.c"
69
70 #include "cpu/x86/mtrr/earlymtrr.c"
71
72 #include "northbridge/amd/amdfam10/setup_resource_map.c"
73
74 #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
75
76 #include "southbridge/nvidia/mcp55/mcp55_early_ctrl.c"
77
78 static inline void activate_spd_rom(const struct mem_controller *ctrl)
79 {
80         /* nothing to do */
81 }
82
83 static inline int spd_read_byte(unsigned device, unsigned address)
84 {
85         return smbus_read_byte(device, address);
86 }
87
88 #include "northbridge/amd/amdfam10/amdfam10.h"
89
90 #include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
91 #include "northbridge/amd/amdfam10/amdfam10_pci.c"
92
93 #include "resourcemap.c"
94
95 #include "cpu/amd/quadcore/quadcore.c"
96
97 #define MCP55_NUM 1
98 #define MCP55_USE_NIC 1
99
100 #define MCP55_PCI_E_X_0 1
101
102 #define MCP55_MB_SETUP \
103         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+37, 0x00, 0x44,/* GPIO38 PCI_REQ3 */ \
104         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+38, 0x00, 0x44,/* GPIO39 PCI_GNT3 */ \
105         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+39, 0x00, 0x44,/* GPIO40 PCI_GNT2 */ \
106         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+40, 0x00, 0x44,/* GPIO41 PCI_REQ2 */ \
107         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+59, 0x00, 0x60,/* GPIP60 FANCTL0 */ \
108         RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+60, 0x00, 0x60,/* GPIO61 FANCTL1 */
109
110 #include "southbridge/nvidia/mcp55/mcp55_early_setup_ss.h"
111 #include "southbridge/nvidia/mcp55/mcp55_early_setup_car.c"
112
113 #include "cpu/amd/car/post_cache_as_ram.c"
114
115 #include "cpu/amd/microcode/microcode.c"
116 #include "cpu/amd/model_10xxx/update_microcode.c"
117 #include "cpu/amd/model_10xxx/init_cpus.c"
118
119
120 #include "southbridge/nvidia/mcp55/mcp55_enable_rom.c"
121 #include "northbridge/amd/amdfam10/early_ht.c"
122
123 static void sio_setup(void)
124 {
125         uint32_t dword;
126         uint8_t byte;
127
128         byte = pci_read_config8(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0x7b);
129         byte |= 0x20;
130         pci_write_config8(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0x7b, byte);
131
132         dword = pci_read_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0xa0);
133         /*serial 0 */
134         dword |= (1<<0);
135         pci_write_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0xa0, dword);
136
137         dword = pci_read_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0xa4);
138         dword |= (1<<16);
139         pci_write_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0xa4, dword);
140 }
141
142 #include "spd_addr.h"
143
144 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
145 {
146         struct sys_info *sysinfo = (struct sys_info *)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
147
148         u32 bsp_apicid = 0;
149         u32 val;
150         u32 wants_reset;
151         msr_t msr;
152
153         if (!cpu_init_detectedx && boot_cpu()) {
154                 /* Nothing special needs to be done to find bus 0 */
155                 /* Allow the HT devices to be found */
156
157                 set_bsp_node_CHtExtNodeCfgEn();
158                 enumerate_ht_chain();
159
160                 sio_setup();
161
162                 /* Setup the mcp55 */
163                 mcp55_enable_rom();
164         }
165
166         post_code(0x30);
167
168         if (bist == 0) {
169                 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
170         }
171
172         post_code(0x32);
173
174         w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
175         uart_init();
176         console_init();
177         printk(BIOS_DEBUG, "\n");
178
179         /* Halt if there was a built in self test failure */
180         report_bist_failure(bist);
181
182 #if CONFIG_USBDEBUG
183         mcp55_enable_usbdebug(DBGP_DEFAULT);
184         early_usbdebug_init();
185 #endif
186
187         val = cpuid_eax(1);
188         printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
189         printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
190         printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
191         printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
192
193         /* Setup sysinfo defaults */
194         set_sysinfo_in_ram(0);
195
196         update_microcode(val);
197         post_code(0x33);
198
199         cpuSetAMDMSR();
200         post_code(0x34);
201
202         amd_ht_init(sysinfo);
203         post_code(0x35);
204
205         /* Setup nodes PCI space and start core 0 AP init. */
206         finalize_node_setup(sysinfo);
207
208         /* Setup any mainboard PCI settings etc. */
209         setup_mb_resource_map();
210         post_code(0x36);
211
212         /* wait for all the APs core0 started by finalize_node_setup. */
213         /* FIXME: A bunch of cores are going to start output to serial at once.
214          * It would be nice to fixup prink spinlocks for ROM XIP mode.
215          * I think it could be done by putting the spinlock flag in the cache
216          * of the BSP located right after sysinfo.
217          */
218         wait_all_core0_started();
219
220 #if CONFIG_LOGICAL_CPUS==1
221         /* Core0 on each node is configured. Now setup any additional cores. */
222         printk(BIOS_DEBUG, "start_other_cores()\n");
223         start_other_cores();
224         post_code(0x37);
225         wait_all_other_cores_started(bsp_apicid);
226 #endif
227
228         post_code(0x38);
229
230 #if SET_FIDVID == 1
231         msr = rdmsr(0xc0010071);
232         printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
233
234         /* FIXME: The sb fid change may survive the warm reset and only
235          * need to be done once.*/
236         enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
237
238         post_code(0x39);
239
240         if (!warm_reset_detect(0)) {                    // BSP is node 0
241                 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
242         } else {
243                 init_fidvid_stage2(bsp_apicid, 0);      // BSP is node 0
244         }
245
246         post_code(0x3A);
247
248         /* show final fid and vid */
249         msr=rdmsr(0xc0010071);
250         printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
251 #endif
252
253         init_timer(); // Need to use TMICT to synconize FID/VID
254
255         wants_reset = mcp55_early_setup_x();
256
257         /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
258         if (!warm_reset_detect(0)) {
259                 print_info("...WARM RESET...\n\n\n");
260                 soft_reset();
261                 die("After soft_reset_x - shouldn't see this message!!!\n");
262         }
263
264         if (wants_reset)
265                 printk(BIOS_DEBUG, "mcp55_early_setup_x wanted additional reset!\n");
266
267         post_code(0x3B);
268
269         /* It's the time to set ctrl in sysinfo now; */
270         printk(BIOS_DEBUG, "fill_mem_ctrl()\n");
271         fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
272         post_code(0x3D);
273
274         printk(BIOS_DEBUG, "enable_smbus()\n");
275         enable_smbus();
276
277         post_code(0x40);
278
279         printk(BIOS_DEBUG, "raminit_amdmct()\n");
280         raminit_amdmct(sysinfo);
281         post_code(0x41);
282
283         printk(BIOS_DEBUG, "\n*** Yes, the copy/decompress is taking a while, FIXME!\n");
284         post_cache_as_ram();    // BSP switch stack to ram, copy then execute LB.
285         post_code(0x43);        // Should never see this post code.
286 }
287