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