blob: f89ea846abc2dce221e7c9eddde9825e01ea78d4 [file] [log] [blame]
Yinghai Lud4b278c2006-10-04 20:46:15 +00001#define RAMINIT_SYSINFO 1
2#define CACHE_AS_RAM_ADDRESS_DEBUG 0
3
Stefan Reinauer14e22772010-04-27 06:56:47 +00004#define SET_NB_CFG_54 1
Yinghai Lud4b278c2006-10-04 20:46:15 +00005
6//used by raminit
7#define QRANK_DIMM_SUPPORT 1
8
9//used by incoherent_ht
Yinghai Lud4b278c2006-10-04 20:46:15 +000010//#define K8_ALLOCATE_IO_RANGE 1
11
Yinghai Lud4b278c2006-10-04 20:46:15 +000012//used by init_cpus and fidvid
Myles Watson9b43afd2010-04-08 15:09:53 +000013#define SET_FIDVID 0
Yinghai Lud4b278c2006-10-04 20:46:15 +000014//if we want to wait for core1 done before DQS training, set it to 0
Myles Watson9b43afd2010-04-08 15:09:53 +000015#define SET_FIDVID_CORE0_ONLY 1
Yinghai Lud4b278c2006-10-04 20:46:15 +000016
Stefan Reinauer08670622009-06-30 15:17:49 +000017#if CONFIG_K8_REV_F_SUPPORT == 1
Yinghai Lud4b278c2006-10-04 20:46:15 +000018#define K8_REV_F_SUPPORT_F0_F1_WORKAROUND 0
Yinghai Lu5f9624d2006-10-04 22:56:21 +000019#endif
Yinghai Lud4b278c2006-10-04 20:46:15 +000020
21#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000022#include <string.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000023#include <device/pci_def.h>
24#include <device/pci_ids.h>
25#include <arch/io.h>
26#include <device/pnp_def.h>
27#include <arch/romcc_io.h>
28#include <cpu/x86/lapic.h>
29#include "option_table.h"
30#include "pc80/mc146818rtc_early.c"
31
Patrick Georgi12584e22010-05-08 09:14:51 +000032#include <console/console.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000033#include <cpu/amd/model_fxx_rev.h>
34#include "southbridge/amd/amd8111/amd8111_early_smbus.c"
Stefan Reinauer8f2c6162010-04-06 21:50:21 +000035#include <reset.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000036#include "northbridge/amd/amdk8/raminit.h"
37#include "cpu/amd/model_fxx/apic_timer.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000038
Yinghai Lud4b278c2006-10-04 20:46:15 +000039#include "cpu/x86/lapic/boot_cpu.c"
40#include "northbridge/amd/amdk8/reset_test.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000041
Yinghai Lu5f9624d2006-10-04 22:56:21 +000042#include "cpu/x86/bist.h"
Yinghai Lud4b278c2006-10-04 20:46:15 +000043
44#include "lib/delay.c"
45
Yinghai Lud4b278c2006-10-04 20:46:15 +000046#include "northbridge/amd/amdk8/debug.c"
Stefan Reinauer8f2c6162010-04-06 21:50:21 +000047#include "cpu/x86/mtrr/earlymtrr.c"
48#include <cpu/amd/mtrr.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000049#include "superio/winbond/w83627hf/w83627hf_early_serial.c"
50
51#include "northbridge/amd/amdk8/setup_resource_map.c"
52
53#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
54
55#include "southbridge/amd/amd8111/amd8111_early_ctrl.c"
56
57static void memreset_setup(void)
58{
59 //GPIO on amd8111 to enable MEMRST ????
60 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=1
61 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 17);
62}
63
64static void memreset(int controllers, const struct mem_controller *ctrl)
65{
66}
67
68static inline void activate_spd_rom(const struct mem_controller *ctrl)
69{
70#define SMBUS_HUB 0x18
71 int ret,i;
72 unsigned device=(ctrl->channel0[0])>>8;
73 /* the very first write always get COL_STS=1 and ABRT_STS=1, so try another time*/
74 i=2;
75 do {
76 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
77 } while ((ret!=0) && (i-->0));
78
79 smbus_write_byte(SMBUS_HUB, 0x03, 0);
80}
81#if 0
82static inline void change_i2c_mux(unsigned device)
83{
84#define SMBUS_HUB 0x18
85 int ret, i;
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000086 print_debug("change_i2c_mux i="); print_debug_hex8(device); print_debug("\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +000087 i=2;
88 do {
89 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000090 print_debug("change_i2c_mux 1 ret="); print_debug_hex32(ret); print_debug("\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +000091 } while ((ret!=0) && (i-->0));
92 ret = smbus_write_byte(SMBUS_HUB, 0x03, 0);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000093 print_debug("change_i2c_mux 2 ret="); print_debug_hex32(ret); print_debug("\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +000094}
95#endif
96
97static inline int spd_read_byte(unsigned device, unsigned address)
98{
99 return smbus_read_byte(device, address);
100}
101
Yinghai Lu5f9624d2006-10-04 22:56:21 +0000102#include "northbridge/amd/amdk8/amdk8.h"
Yinghai Lud4b278c2006-10-04 20:46:15 +0000103#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauer23836e22010-04-15 12:39:29 +0000104#include "northbridge/amd/amdk8/coherent_ht.c"
Myles Watson17257032009-06-04 20:18:42 +0000105#include "northbridge/amd/amdk8/raminit_f.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +0000106#include "lib/generic_sdram.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +0000107
108 /* tyan does not want the default */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000109#include "resourcemap.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +0000110
111#include "cpu/amd/dualcore/dualcore.c"
112
113#define RC0 ((1<<0)<<8)
114#define RC1 ((1<<1)<<8)
115#define RC2 ((1<<2)<<8)
116#define RC3 ((1<<3)<<8)
117
118#define DIMM0 0x50
119#define DIMM1 0x51
120#define DIMM2 0x52
121#define DIMM3 0x53
122#define DIMM4 0x54
123#define DIMM5 0x55
124#define DIMM6 0x56
125#define DIMM7 0x57
126
Stefan Reinauer853263b2010-04-09 10:43:49 +0000127
Yinghai Lud4b278c2006-10-04 20:46:15 +0000128#include "cpu/amd/car/post_cache_as_ram.c"
129
130#include "cpu/amd/model_fxx/init_cpus.c"
131
132#include "cpu/amd/model_fxx/fidvid.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +0000133
Yinghai Lud4b278c2006-10-04 20:46:15 +0000134#include "southbridge/amd/amd8111/amd8111_enable_rom.c"
135#include "northbridge/amd/amdk8/early_ht.c"
136
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000137void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000138{
139 static const uint16_t spd_addr[] = {
140 //first node
141 RC0|DIMM0, RC0|DIMM2, 0, 0,
142 RC0|DIMM1, RC0|DIMM3, 0, 0,
143#if CONFIG_MAX_PHYSICAL_CPUS > 1
144 //second node
145 RC1|DIMM0, RC1|DIMM2, RC1|DIMM4, RC1|DIMM6,
146 RC1|DIMM1, RC1|DIMM3, RC1|DIMM5, RC1|DIMM7,
147#endif
148#if CONFIG_MAX_PHYSICAL_CPUS > 2
149 // third node
150 RC2|DIMM0, RC2|DIMM2, 0, 0,
151 RC2|DIMM1, RC2|DIMM3, 0, 0,
152 // four node
153 RC3|DIMM0, RC3|DIMM2, RC3|DIMM4, RC3|DIMM6,
154 RC3|DIMM1, RC3|DIMM3, RC3|DIMM5, RC3|DIMM7,
155#endif
156
157 };
158
Myles Watson6e235762009-09-29 14:56:15 +0000159 struct sys_info *sysinfo = (void*)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000160
Myles Watson6e235762009-09-29 14:56:15 +0000161 int needs_reset;
Yinghai Lud4b278c2006-10-04 20:46:15 +0000162 unsigned bsp_apicid = 0;
Myles Watson9b43afd2010-04-08 15:09:53 +0000163#if SET_FIDVID == 1
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000164 struct cpuid_result cpuid1;
Myles Watson6e235762009-09-29 14:56:15 +0000165#endif
Yinghai Lud4b278c2006-10-04 20:46:15 +0000166
Patrick Georgi2bd91002010-03-18 16:46:50 +0000167 if (!cpu_init_detectedx && boot_cpu()) {
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000168 /* Nothing special needs to be done to find bus 0 */
169 /* Allow the HT devices to be found */
170
171 enumerate_ht_chain();
172
173 /* Setup the rom access for 4M */
174 amd8111_enable_rom();
175 }
176
Yinghai Lud4b278c2006-10-04 20:46:15 +0000177 if (bist == 0) {
Yinghai Lud4b278c2006-10-04 20:46:15 +0000178 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
179 }
180
181// post_code(0x32);
182
Stefan Reinauer08670622009-06-30 15:17:49 +0000183 w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000184 uart_init();
185 console_init();
186
Stefan Reinauer08670622009-06-30 15:17:49 +0000187// dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000188
Yinghai Lud4b278c2006-10-04 20:46:15 +0000189 /* Halt if there was a built in self test failure */
190 report_bist_failure(bist);
191
Myles Watson08e0fb82010-03-22 16:33:25 +0000192 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000193
Yinghai Lu5f9624d2006-10-04 22:56:21 +0000194 setup_mb_resource_map();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000195#if 0
196 dump_pci_device(PCI_DEV(0, 0x18, 0));
197 dump_pci_device(PCI_DEV(0, 0x19, 0));
198#endif
199
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000200 print_debug("bsp_apicid="); print_debug_hex8(bsp_apicid); print_debug("\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +0000201
Stefan Reinauer08670622009-06-30 15:17:49 +0000202#if CONFIG_MEM_TRAIN_SEQ == 1
Stefan Reinauer14e22772010-04-27 06:56:47 +0000203 set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram
Yinghai Lud4b278c2006-10-04 20:46:15 +0000204#endif
205 setup_coherent_ht_domain(); // routing table and start other core0
206
207 wait_all_core0_started();
208#if CONFIG_LOGICAL_CPUS==1
209 // It is said that we should start core1 after all core0 launched
Stefan Reinauer14e22772010-04-27 06:56:47 +0000210 /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
Yinghai Lud4b278c2006-10-04 20:46:15 +0000211 * So here need to make sure last core0 is started, esp for two way system,
Stefan Reinauer14e22772010-04-27 06:56:47 +0000212 * (there may be apic id conflicts in that case)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000213 */
214 start_other_cores();
215 wait_all_other_cores_started(bsp_apicid);
216#endif
Stefan Reinauer14e22772010-04-27 06:56:47 +0000217
Yinghai Lud4b278c2006-10-04 20:46:15 +0000218 /* it will set up chains and store link pair for optimization later */
219 ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
220
221#if 0
222 //it your CPU min fid is 1G, you can change HT to 1G and FID to max one time.
223 needs_reset = optimize_link_coherent_ht();
224 needs_reset |= optimize_link_incoherent_ht(sysinfo);
225#endif
226
Myles Watson9b43afd2010-04-08 15:09:53 +0000227#if SET_FIDVID == 1
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000228 /* Check to see if processor is capable of changing FIDVID */
229 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
230 cpuid1 = cpuid(0x80000007);
231 if( (cpuid1.edx & 0x6) == 0x6 ) {
Yinghai Lud4b278c2006-10-04 20:46:15 +0000232
233 {
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000234 /* Read FIDVID_STATUS */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000235 msr_t msr;
236 msr=rdmsr(0xc0010042);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000237 print_debug("begin msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +0000238
239 }
240
241 enable_fid_change();
242
243 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
244
245 init_fidvid_bsp(bsp_apicid);
246
247 // show final fid and vid
248 {
249 msr_t msr;
250 msr=rdmsr(0xc0010042);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000251 print_debug("end msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +0000252
253 }
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000254
255 } else {
256 print_debug("Changing FIDVID not supported\n");
257 }
258
Yinghai Lud4b278c2006-10-04 20:46:15 +0000259#endif
260
261#if 1
262 needs_reset = optimize_link_coherent_ht();
263 needs_reset |= optimize_link_incoherent_ht(sysinfo);
264
265 // fidvid change will issue one LDTSTOP and the HT change will be effective too
266 if (needs_reset) {
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000267 print_info("ht reset -\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +0000268 soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn);
269 }
270#endif
271 allow_all_aps_stop(bsp_apicid);
272
Yinghai Lud4b278c2006-10-04 20:46:15 +0000273 //It's the time to set ctrl in sysinfo now;
274 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000275
276 enable_smbus();
277
278#if 0
Myles Watson6e235762009-09-29 14:56:15 +0000279 int i;
Yinghai Lud4b278c2006-10-04 20:46:15 +0000280 for(i=0;i<4;i++) {
281 activate_spd_rom(&cpu[i]);
282 dump_smbus_registers();
283 }
284#endif
285
286#if 0
287 for(i=1;i<256;i<<=1) {
288 change_i2c_mux(i);
289 dump_smbus_registers();
290 }
291#endif
292
293 memreset_setup();
294
295 //do we need apci timer, tsc...., only debug need it for better output
296 /* all ap stopped? */
297// init_timer(); // Need to use TMICT to synconize FID/VID
298
299 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
300
301#if 0
302 print_pci_devices();
303#endif
304
305#if 0
306// dump_pci_devices();
307 dump_pci_device_index_wait(PCI_DEV(0, 0x18, 2), 0x98);
308 dump_pci_device_index_wait(PCI_DEV(0, 0x19, 2), 0x98);
309#endif
310
311 post_cache_as_ram(); // bsp swtich stack to ram and copy sysinfo ram now
312
313}
Stefan Reinauer798ef282010-03-29 22:08:01 +0000314