blob: 599a01a37e2ce356d22a5ba6e2351e689bfe5f16 [file] [log] [blame]
bxshifaea4c52006-11-02 16:02:33 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
bxshifaea4c52006-11-02 16:02:33 +00003 *
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) 2006 MSI
9 * Written by bxshi <bingxunshi@gmail.com> for MSI.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
bxshifaea4c52006-11-02 16:02:33 +000026#define SET_NB_CFG_54 1
27
bxshifaea4c52006-11-02 16:02:33 +000028#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000029#include <string.h>
bxshifaea4c52006-11-02 16:02:33 +000030#include <device/pci_def.h>
31#include <device/pci_ids.h>
32#include <arch/io.h>
33#include <device/pnp_def.h>
34#include <arch/romcc_io.h>
35#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000036#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000037#include <console/console.h>
bxshifaea4c52006-11-02 16:02:33 +000038
bxshifaea4c52006-11-02 16:02:33 +000039#include <cpu/amd/model_fxx_rev.h>
40#include "southbridge/broadcom/bcm5785/bcm5785_early_smbus.c"
Patrick Georgi9d4212f2010-10-26 15:51:57 +000041#include "southbridge/broadcom/bcm5785/bcm5785_enable_rom.c"
bxshifaea4c52006-11-02 16:02:33 +000042#include "northbridge/amd/amdk8/raminit.h"
43#include "cpu/amd/model_fxx/apic_timer.c"
44#include "lib/delay.c"
Stefan Reinauerc51dc442010-04-07 01:44:04 +000045#include <reset.h>
bxshifaea4c52006-11-02 16:02:33 +000046
bxshifaea4c52006-11-02 16:02:33 +000047#include "cpu/x86/lapic/boot_cpu.c"
48#include "northbridge/amd/amdk8/reset_test.c"
49#include "northbridge/amd/amdk8/debug.c"
50#include "superio/nsc/pc87417/pc87417_early_serial.c"
Stefan Reinauer5d3dee82010-04-14 11:40:34 +000051#include "cpu/x86/mtrr/earlymtrr.c"
bxshifaea4c52006-11-02 16:02:33 +000052#include "cpu/x86/bist.h"
53
54#include "northbridge/amd/amdk8/setup_resource_map.c"
55
56#define SERIAL_DEV PNP_DEV(0x2e, PC87417_SP1)
57#define RTC_DEV PNP_DEV(0x2e, PC87417_RTC)
58#include "southbridge/broadcom/bcm5785/bcm5785_early_setup.c"
bxshifaea4c52006-11-02 16:02:33 +000059
60static void memreset(int controllers, const struct mem_controller *ctrl)
61{
62}
63
64static inline void activate_spd_rom(const struct mem_controller *ctrl)
65{
66#define SMBUS_SWITCH1 0x70
67#define SMBUS_SWITCH2 0x72
68 unsigned device = (ctrl->channel0[0]) >> 8;
69 smbus_send_byte(SMBUS_SWITCH1, device & 0x0f);
70 smbus_send_byte(SMBUS_SWITCH2, (device >> 4) & 0x0f );
71}
72
73#if 0
74static inline void change_i2c_mux(unsigned device)
75{
76#define SMBUS_SWITCH1 0x70
77#define SMBUS_SWITCH2 0x72
78 smbus_send_byte(SMBUS_SWITCH1, device & 0x0f);
79 smbus_send_byte(SMBUS_SWITCH2, (device >> 4) & 0x0f );
80}
81#endif
82
bxshifaea4c52006-11-02 16:02:33 +000083static inline int spd_read_byte(unsigned device, unsigned address)
84{
85 return smbus_read_byte(device, address);
86}
87
88#include "northbridge/amd/amdk8/amdk8_f.h"
bxshifaea4c52006-11-02 16:02:33 +000089#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauer23836e22010-04-15 12:39:29 +000090#include "northbridge/amd/amdk8/coherent_ht.c"
bxshifaea4c52006-11-02 16:02:33 +000091#include "northbridge/amd/amdk8/raminit_f.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000092#include "lib/generic_sdram.c"
bxshifaea4c52006-11-02 16:02:33 +000093
94 /* msi does not want the default */
95#include "resourcemap.c"
96
97#include "cpu/amd/dualcore/dualcore.c"
98
99#define RC0 (0x10<<8)
100#define RC1 (0x01<<8)
101
102#define DIMM0 0x50
103#define DIMM1 0x51
104#define DIMM2 0x52
105#define DIMM3 0x53
106#define DIMM4 0x54
107#define DIMM5 0x55
108#define DIMM6 0x56
109#define DIMM7 0x57
110
bxshifaea4c52006-11-02 16:02:33 +0000111#include "cpu/amd/car/post_cache_as_ram.c"
112
113#include "cpu/amd/model_fxx/init_cpus.c"
114
115#include "cpu/amd/model_fxx/fidvid.c"
116
bxshifaea4c52006-11-02 16:02:33 +0000117#include "northbridge/amd/amdk8/early_ht.c"
118
bxshifaea4c52006-11-02 16:02:33 +0000119void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
120{
bxshifaea4c52006-11-02 16:02:33 +0000121 static const uint16_t spd_addr[] = {
122 //first node
123 RC0|DIMM0, RC0|DIMM2, RC0|DIMM4, RC0|DIMM6,
124 RC0|DIMM1, RC0|DIMM3, RC0|DIMM5, RC0|DIMM7,
bxshifaea4c52006-11-02 16:02:33 +0000125 //second node
126 RC1|DIMM0, RC1|DIMM2, RC1|DIMM4, RC1|DIMM6,
127 RC1|DIMM1, RC1|DIMM3, RC1|DIMM5, RC1|DIMM7,
bxshifaea4c52006-11-02 16:02:33 +0000128 };
129
Stefan Reinauerc51dc442010-04-07 01:44:04 +0000130 struct sys_info *sysinfo = (struct sys_info *)(CONFIG_DCACHE_RAM_BASE +
131 CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
bxshifaea4c52006-11-02 16:02:33 +0000132
133 int needs_reset;
134 unsigned bsp_apicid = 0;
135
Patrick Georgi2bd91002010-03-18 16:46:50 +0000136 if (!cpu_init_detectedx && boot_cpu()) {
Patrick Georgi776b85b2010-03-18 16:18:58 +0000137 /* Nothing special needs to be done to find bus 0 */
138 /* Allow the HT devices to be found */
139
140 enumerate_ht_chain();
141
142 bcm5785_enable_rom();
143
144 bcm5785_enable_lpc();
145
146 //enable RTC
147 pc87417_enable_dev(RTC_DEV);
148 }
149
bxshifaea4c52006-11-02 16:02:33 +0000150 if (bist == 0) {
151 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
152 }
153
154// post_code(0x32);
155
Stefan Reinauer08670622009-06-30 15:17:49 +0000156 pc87417_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
bxshifaea4c52006-11-02 16:02:33 +0000157 uart_init();
158 console_init();
159
Stefan Reinauer08670622009-06-30 15:17:49 +0000160// dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE);
bxshifaea4c52006-11-02 16:02:33 +0000161
162 /* Halt if there was a built in self test failure */
163 report_bist_failure(bist);
164
Myles Watson08e0fb82010-03-22 16:33:25 +0000165 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
bxshifaea4c52006-11-02 16:02:33 +0000166
167 setup_ms9185_resource_map();
168#if 0
169 dump_pci_device(PCI_DEV(0, 0x18, 0));
170 dump_pci_device(PCI_DEV(0, 0x19, 0));
171#endif
172
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000173 print_debug("bsp_apicid="); print_debug_hex8(bsp_apicid); print_debug("\n");
bxshifaea4c52006-11-02 16:02:33 +0000174
175 setup_coherent_ht_domain();
176
177 wait_all_core0_started();
178#if CONFIG_LOGICAL_CPUS==1
179 // It is said that we should start core1 after all core0 launched
180 /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
181 * So here need to make sure last core0 is started, esp for two way system,
182 * (there may be apic id conflicts in that case)
183 */
184 start_other_cores();
185//bx_a010- wait_all_other_cores_started(bsp_apicid);
186#endif
187
188 /* it will set up chains and store link pair for optimization later */
189 ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
190
191 bcm5785_early_setup();
192
bxshifaea4c52006-11-02 16:02:33 +0000193#if 0
194 //it your CPU min fid is 1G, you can change HT to 1G and FID to max one time.
195 needs_reset = optimize_link_coherent_ht();
196 needs_reset |= optimize_link_incoherent_ht(sysinfo);
197#endif
198
Patrick Georgi76e81522010-11-16 21:25:29 +0000199#if CONFIG_SET_FIDVID
bxshifaea4c52006-11-02 16:02:33 +0000200
201 {
202 msr_t msr;
203 msr=rdmsr(0xc0010042);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000204 print_debug("begin msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\n");
bxshifaea4c52006-11-02 16:02:33 +0000205
206 }
207
208 enable_fid_change();
209
210 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
211
212 init_fidvid_bsp(bsp_apicid);
213
214 // show final fid and vid
215 {
216 msr_t msr;
217 msr=rdmsr(0xc0010042);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000218 print_debug("end msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\n");
bxshifaea4c52006-11-02 16:02:33 +0000219
220 }
221#endif
222
223#if 1
224 needs_reset = optimize_link_coherent_ht();
225 needs_reset |= optimize_link_incoherent_ht(sysinfo);
226
227 // fidvid change will issue one LDTSTOP and the HT change will be effective too
228 if (needs_reset) {
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000229 print_info("ht reset -\n");
bxshifaea4c52006-11-02 16:02:33 +0000230 soft_reset();
231 }
232#endif
233 allow_all_aps_stop(bsp_apicid);
234
235 //It's the time to set ctrl in sysinfo now;
236 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
237
238 enable_smbus();
239
240#if 0
241 int i;
242 for(i=0;i<2;i++) {
243 activate_spd_rom(sysinfo->ctrl+i);
244 dump_smbus_registers();
245 }
246#endif
247
248#if 0
249 int i;
250 for(i=1;i<256;i<<=1) {
251 change_i2c_mux(i);
252 dump_smbus_registers();
253 }
254#endif
255
bxshifaea4c52006-11-02 16:02:33 +0000256 //do we need apci timer, tsc...., only debug need it for better output
257 /* all ap stopped? */
258// init_timer(); // Need to use TMICT to synconize FID/VID
259
260 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
261
262#if 0
263 print_pci_devices();
264#endif
265
266#if 0
267// dump_pci_devices();
268 dump_pci_device_index_wait(PCI_DEV(0, 0x18, 2), 0x98);
269 dump_pci_device_index_wait(PCI_DEV(0, 0x19, 2), 0x98);
270#endif
271
272 post_cache_as_ram();
273
bxshifaea4c52006-11-02 16:02:33 +0000274}
Stefan Reinauer798ef282010-03-29 22:08:01 +0000275