e8fde50320cb95c3379b1ebf47c3431762a53cef
[coreboot.git] / src / mainboard / hp / dl165_g6_fam10 / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2006 Tyan
5  * Copyright (C) 2006 AMD
6  * Written by Yinghai Lu <yinghailu@gmail.com> for Tyan and AMD.
7  *
8  * Copyright (C) 2007 University of Mannheim
9  * Written by Philipp Degler <pdegler@rumms.uni-mannheim.de> for University of Mannheim
10  * Copyright (C) 2009 University of Heidelberg
11  * Written by Mondrian Nuessle <nuessle@uni-heidelberg.de> for University of Heidelberg
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
26  */
27
28 #define FAM10_SCAN_PCI_BUS 0
29 #define FAM10_ALLOCATE_IO_RANGE 1
30
31 #include <stdint.h>
32 #include <string.h>
33 #include <device/pci_def.h>
34 #include <device/pci_ids.h>
35 #include <arch/io.h>
36 #include <device/pnp_def.h>
37 #include <arch/romcc_io.h>
38 #include <cpu/x86/lapic.h>
39 #include "option_table.h"
40 #include <console/console.h>
41 #include <cpu/amd/model_10xxx_rev.h>
42 #include "southbridge/broadcom/bcm5785/bcm5785_early_smbus.c"
43 #include "southbridge/broadcom/bcm5785/bcm5785_enable_rom.c"
44 #include "northbridge/amd/amdfam10/raminit.h"
45 #include "northbridge/amd/amdfam10/amdfam10.h"
46 #include <lib.h>
47
48 #include "cpu/amd/model_10xxx/apic_timer.c"
49 #include "lib/delay.c"
50 #include "cpu/x86/lapic/boot_cpu.c"
51 #include "northbridge/amd/amdfam10/reset_test.c"
52
53 #include "superio/serverengines/pilot/pilot_early_serial.c"
54 #include "superio/serverengines/pilot/pilot_early_init.c"
55 #include "superio/nsc/pc87417/pc87417_early_serial.c"
56
57 #include "cpu/x86/bist.h"
58
59 #include "northbridge/amd/amdfam10/debug.c"
60
61 #include "cpu/x86/mtrr/earlymtrr.c"
62
63 //#include "northbridge/amd/amdfam10/setup_resource_map.c"
64
65 #define SERIAL_DEV PNP_DEV(0x2e, PILOT_SP1)
66 #define RTC_DEV PNP_DEV(0x4e, PC87417_RTC)
67
68 #include "southbridge/broadcom/bcm5785/bcm5785_early_setup.c"
69
70 static inline void activate_spd_rom(const struct mem_controller *ctrl)
71 {
72         u8 val;
73         outb(0x3d, 0x0cd6);
74         outb(0x87, 0x0cd7);
75
76         outb(0x44, 0xcd6);
77         val = inb(0xcd7);
78         outb((val & ~3) | ctrl->spd_switch_addr, 0xcd7);
79 }
80
81 static inline int spd_read_byte(unsigned device, unsigned address)
82 {
83         return smbus_read_byte(device, address);
84 }
85
86 #include "northbridge/amd/amdfam10/amdfam10.h"
87
88 #include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
89 #include "northbridge/amd/amdfam10/amdfam10_pci.c"
90
91 #include "cpu/amd/quadcore/quadcore.c"
92
93 #include "cpu/amd/car/post_cache_as_ram.c"
94
95 #include "cpu/amd/microcode/microcode.c"
96 #include "cpu/amd/model_10xxx/update_microcode.c"
97 #include "cpu/amd/model_10xxx/init_cpus.c"
98
99 #include "northbridge/amd/amdfam10/early_ht.c"
100
101 #include "spd_addr.h"
102
103 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
104 {
105         struct sys_info *sysinfo =  (struct sys_info *)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
106
107
108         u32 bsp_apicid = 0;
109         u32 val;
110         msr_t msr;
111  
112         if (!cpu_init_detectedx && boot_cpu()) {
113             /* Nothing special needs to be done to find bus 0 */
114                 /* Allow the HT devices to be found */
115                 /* mov bsp to bus 0xff when > 8 nodes */
116                 set_bsp_node_CHtExtNodeCfgEn();
117                 enumerate_ht_chain();
118
119                 /* Setup the rom access for 4M */
120                 bcm5785_enable_rom();
121                 bcm5785_enable_lpc();
122                 //enable RTC
123                 pc87417_enable_dev(RTC_DEV);
124         }
125
126         post_code(0x30);
127
128         if (bist == 0) {
129                 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
130         }
131
132         pilot_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
133
134         uart_init();
135
136         /* Halt if there was a built in self test failure */
137         report_bist_failure(bist);
138
139         console_init();
140         pilot_early_init(SERIAL_DEV); //config port is being taken from SERIAL_DEV
141
142         val = cpuid_eax(1);
143         printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
144         printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
145         printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
146         printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
147
148         /* Setup sysinfo defaults */
149         set_sysinfo_in_ram(0);
150
151         update_microcode(val);
152         post_code(0x33);
153
154         cpuSetAMDMSR();
155         post_code(0x34);
156
157         amd_ht_init(sysinfo);
158         post_code(0x35);
159
160         /* Setup nodes PCI space and start core 0 AP init. */
161         finalize_node_setup(sysinfo);
162
163         post_code(0x36);
164
165         /* wait for all the APs core0 started by finalize_node_setup. */
166         /* FIXME: A bunch of cores are going to start output to serial at once.
167          * It would be nice to fixup prink spinlocks for ROM XIP mode.
168          * I think it could be done by putting the spinlock flag in the cache
169          * of the BSP located right after sysinfo.
170          */
171
172         wait_all_core0_started();
173
174 #if CONFIG_LOGICAL_CPUS==1
175         /* Core0 on each node is configured. Now setup any additional cores. */
176         printk(BIOS_DEBUG, "start_other_cores()\n");
177         start_other_cores();
178         post_code(0x37);
179         wait_all_other_cores_started(bsp_apicid);
180 #endif
181
182 #if CONFIG_SET_FIDVID
183         msr = rdmsr(0xc0010071);
184         printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
185
186         /* FIXME: The sb fid change may survive the warm reset and only
187          * need to be done once.*/
188
189         enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
190
191         post_code(0x39);
192
193         if (!warm_reset_detect(0)) {                    // BSP is node 0
194                 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
195         } else {
196                 init_fidvid_stage2(bsp_apicid, 0);      // BSP is node 0
197         }
198
199         post_code(0x3A);
200
201         /* show final fid and vid */
202         msr=rdmsr(0xc0010071);
203         printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
204 #endif
205
206         init_timer();
207
208         /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
209         if (!warm_reset_detect(0)) {
210                 print_info("...WARM RESET...\n\n\n");
211                 soft_reset();
212                 die("After soft_reset_x - shouldn't see this message!!!\n");
213         }
214
215         /* It's the time to set ctrl in sysinfo now; */
216         fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
217         enable_smbus();
218
219         //do we need apci timer, tsc...., only debug need it for better output
220         /* all ap stopped? */
221 //      init_timer(); // Need to use TMICT to synconize FID/VID
222
223         printk(BIOS_DEBUG, "raminit_amdmct()\n");
224         raminit_amdmct(sysinfo);
225         post_code(0x41);
226
227         bcm5785_early_setup();
228
229         post_cache_as_ram();
230 }