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