blob: 24a6525e58eeb415d3c8459bf1c75c1ccd80ab66 [file] [log] [blame]
Stefan Reinauer08670622009-06-30 15:17:49 +00001#if CONFIG_K8_REV_F_SUPPORT == 1
Yinghai Lud4b278c2006-10-04 20:46:15 +00002#define K8_REV_F_SUPPORT_F0_F1_WORKAROUND 0
Yinghai Lu5f9624d2006-10-04 22:56:21 +00003#endif
Yinghai Lud4b278c2006-10-04 20:46:15 +00004
5#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +00006#include <string.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +00007#include <device/pci_def.h>
8#include <device/pci_ids.h>
9#include <arch/io.h>
10#include <device/pnp_def.h>
11#include <arch/romcc_io.h>
12#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000013#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000014#include <console/console.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000015#include <cpu/amd/model_fxx_rev.h>
16#include "southbridge/amd/amd8111/amd8111_early_smbus.c"
Stefan Reinauer8f2c6162010-04-06 21:50:21 +000017#include <reset.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000018#include "northbridge/amd/amdk8/raminit.h"
19#include "cpu/amd/model_fxx/apic_timer.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000020#include "cpu/x86/lapic/boot_cpu.c"
21#include "northbridge/amd/amdk8/reset_test.c"
Yinghai Lu5f9624d2006-10-04 22:56:21 +000022#include "cpu/x86/bist.h"
Yinghai Lud4b278c2006-10-04 20:46:15 +000023#include "lib/delay.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000024#include "northbridge/amd/amdk8/debug.c"
Stefan Reinauer8f2c6162010-04-06 21:50:21 +000025#include "cpu/x86/mtrr/earlymtrr.c"
26#include <cpu/amd/mtrr.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000027#include "superio/winbond/w83627hf/w83627hf_early_serial.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000028#include "northbridge/amd/amdk8/setup_resource_map.c"
Uwe Hermann57b2ff82010-11-21 17:29:59 +000029#include "southbridge/amd/amd8111/amd8111_early_ctrl.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000030
31#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
32
Yinghai Lud4b278c2006-10-04 20:46:15 +000033static void memreset_setup(void)
34{
35 //GPIO on amd8111 to enable MEMRST ????
Uwe Hermann7b997052010-11-21 22:47:22 +000036 outb((1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=1
37 outb((1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 17);
Yinghai Lud4b278c2006-10-04 20:46:15 +000038}
39
Uwe Hermann7b997052010-11-21 22:47:22 +000040static void memreset(int controllers, const struct mem_controller *ctrl) { }
Yinghai Lud4b278c2006-10-04 20:46:15 +000041
42static inline void activate_spd_rom(const struct mem_controller *ctrl)
43{
44#define SMBUS_HUB 0x18
45 int ret,i;
46 unsigned device=(ctrl->channel0[0])>>8;
47 /* the very first write always get COL_STS=1 and ABRT_STS=1, so try another time*/
48 i=2;
49 do {
50 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
51 } while ((ret!=0) && (i-->0));
52
53 smbus_write_byte(SMBUS_HUB, 0x03, 0);
54}
Uwe Hermann7b997052010-11-21 22:47:22 +000055
Yinghai Lud4b278c2006-10-04 20:46:15 +000056#if 0
57static inline void change_i2c_mux(unsigned device)
58{
59#define SMBUS_HUB 0x18
60 int ret, i;
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000061 print_debug("change_i2c_mux i="); print_debug_hex8(device); print_debug("\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +000062 i=2;
63 do {
64 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000065 print_debug("change_i2c_mux 1 ret="); print_debug_hex32(ret); print_debug("\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +000066 } while ((ret!=0) && (i-->0));
67 ret = smbus_write_byte(SMBUS_HUB, 0x03, 0);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000068 print_debug("change_i2c_mux 2 ret="); print_debug_hex32(ret); print_debug("\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +000069}
70#endif
71
72static inline int spd_read_byte(unsigned device, unsigned address)
73{
74 return smbus_read_byte(device, address);
75}
76
Yinghai Lu5f9624d2006-10-04 22:56:21 +000077#include "northbridge/amd/amdk8/amdk8.h"
Yinghai Lud4b278c2006-10-04 20:46:15 +000078#include "northbridge/amd/amdk8/incoherent_ht.c"
Stefan Reinauer23836e22010-04-15 12:39:29 +000079#include "northbridge/amd/amdk8/coherent_ht.c"
Myles Watson17257032009-06-04 20:18:42 +000080#include "northbridge/amd/amdk8/raminit_f.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000081#include "lib/generic_sdram.c"
Uwe Hermann7b997052010-11-21 22:47:22 +000082#include "resourcemap.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000083#include "cpu/amd/dualcore/dualcore.c"
Patrick Georgi9bd9a902010-11-20 10:31:00 +000084#include <spd.h>
Uwe Hermann57b2ff82010-11-21 17:29:59 +000085#include "cpu/amd/car/post_cache_as_ram.c"
86#include "cpu/amd/model_fxx/init_cpus.c"
87#include "cpu/amd/model_fxx/fidvid.c"
88#include "southbridge/amd/amd8111/amd8111_enable_rom.c"
89#include "northbridge/amd/amdk8/early_ht.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000090
91#define RC0 ((1<<0)<<8)
92#define RC1 ((1<<1)<<8)
93#define RC2 ((1<<2)<<8)
94#define RC3 ((1<<3)<<8)
95
Patrick Georgice6fb1e2010-03-17 22:44:39 +000096void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
Yinghai Lud4b278c2006-10-04 20:46:15 +000097{
98 static const uint16_t spd_addr[] = {
99 //first node
100 RC0|DIMM0, RC0|DIMM2, 0, 0,
101 RC0|DIMM1, RC0|DIMM3, 0, 0,
102#if CONFIG_MAX_PHYSICAL_CPUS > 1
103 //second node
104 RC1|DIMM0, RC1|DIMM2, RC1|DIMM4, RC1|DIMM6,
105 RC1|DIMM1, RC1|DIMM3, RC1|DIMM5, RC1|DIMM7,
106#endif
107#if CONFIG_MAX_PHYSICAL_CPUS > 2
108 // third node
109 RC2|DIMM0, RC2|DIMM2, 0, 0,
110 RC2|DIMM1, RC2|DIMM3, 0, 0,
111 // four node
112 RC3|DIMM0, RC3|DIMM2, RC3|DIMM4, RC3|DIMM6,
113 RC3|DIMM1, RC3|DIMM3, RC3|DIMM5, RC3|DIMM7,
114#endif
115
116 };
117
Myles Watson6e235762009-09-29 14:56:15 +0000118 struct sys_info *sysinfo = (void*)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
Myles Watson6e235762009-09-29 14:56:15 +0000119 int needs_reset;
Yinghai Lud4b278c2006-10-04 20:46:15 +0000120 unsigned bsp_apicid = 0;
Patrick Georgi76e81522010-11-16 21:25:29 +0000121#if CONFIG_SET_FIDVID
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000122 struct cpuid_result cpuid1;
Myles Watson6e235762009-09-29 14:56:15 +0000123#endif
Yinghai Lud4b278c2006-10-04 20:46:15 +0000124
Patrick Georgi2bd91002010-03-18 16:46:50 +0000125 if (!cpu_init_detectedx && boot_cpu()) {
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000126 /* Nothing special needs to be done to find bus 0 */
127 /* Allow the HT devices to be found */
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000128 enumerate_ht_chain();
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000129 amd8111_enable_rom();
130 }
131
Uwe Hermann7b997052010-11-21 22:47:22 +0000132 if (bist == 0)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000133 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000134
Stefan Reinauer08670622009-06-30 15:17:49 +0000135 w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000136 uart_init();
137 console_init();
138
Stefan Reinauer08670622009-06-30 15:17:49 +0000139// 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 +0000140
Yinghai Lud4b278c2006-10-04 20:46:15 +0000141 /* Halt if there was a built in self test failure */
142 report_bist_failure(bist);
143
Myles Watson08e0fb82010-03-22 16:33:25 +0000144 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000145
Yinghai Lu5f9624d2006-10-04 22:56:21 +0000146 setup_mb_resource_map();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000147#if 0
148 dump_pci_device(PCI_DEV(0, 0x18, 0));
149 dump_pci_device(PCI_DEV(0, 0x19, 0));
150#endif
151
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000152 print_debug("bsp_apicid="); print_debug_hex8(bsp_apicid); print_debug("\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +0000153
Stefan Reinauer08670622009-06-30 15:17:49 +0000154#if CONFIG_MEM_TRAIN_SEQ == 1
Stefan Reinauer14e22772010-04-27 06:56:47 +0000155 set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram
Yinghai Lud4b278c2006-10-04 20:46:15 +0000156#endif
157 setup_coherent_ht_domain(); // routing table and start other core0
158
159 wait_all_core0_started();
160#if CONFIG_LOGICAL_CPUS==1
161 // It is said that we should start core1 after all core0 launched
Stefan Reinauer14e22772010-04-27 06:56:47 +0000162 /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
Yinghai Lud4b278c2006-10-04 20:46:15 +0000163 * So here need to make sure last core0 is started, esp for two way system,
Stefan Reinauer14e22772010-04-27 06:56:47 +0000164 * (there may be apic id conflicts in that case)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000165 */
166 start_other_cores();
167 wait_all_other_cores_started(bsp_apicid);
168#endif
Stefan Reinauer14e22772010-04-27 06:56:47 +0000169
Yinghai Lud4b278c2006-10-04 20:46:15 +0000170 /* it will set up chains and store link pair for optimization later */
171 ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
172
173#if 0
174 //it your CPU min fid is 1G, you can change HT to 1G and FID to max one time.
175 needs_reset = optimize_link_coherent_ht();
176 needs_reset |= optimize_link_incoherent_ht(sysinfo);
177#endif
178
Patrick Georgi76e81522010-11-16 21:25:29 +0000179#if CONFIG_SET_FIDVID
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000180 /* Check to see if processor is capable of changing FIDVID */
181 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
182 cpuid1 = cpuid(0x80000007);
Uwe Hermann7b997052010-11-21 22:47:22 +0000183 if ((cpuid1.edx & 0x6) == 0x6) {
Yinghai Lud4b278c2006-10-04 20:46:15 +0000184
185 {
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000186 /* Read FIDVID_STATUS */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000187 msr_t msr;
188 msr=rdmsr(0xc0010042);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000189 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 +0000190 }
191
192 enable_fid_change();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000193 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000194 init_fidvid_bsp(bsp_apicid);
195
196 // show final fid and vid
197 {
198 msr_t msr;
199 msr=rdmsr(0xc0010042);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000200 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 +0000201 }
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000202
203 } else {
204 print_debug("Changing FIDVID not supported\n");
205 }
Yinghai Lud4b278c2006-10-04 20:46:15 +0000206#endif
207
208#if 1
209 needs_reset = optimize_link_coherent_ht();
210 needs_reset |= optimize_link_incoherent_ht(sysinfo);
211
212 // fidvid change will issue one LDTSTOP and the HT change will be effective too
213 if (needs_reset) {
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000214 print_info("ht reset -\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +0000215 soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn);
216 }
217#endif
218 allow_all_aps_stop(bsp_apicid);
219
Yinghai Lud4b278c2006-10-04 20:46:15 +0000220 //It's the time to set ctrl in sysinfo now;
221 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000222
223 enable_smbus();
224
225#if 0
Myles Watson6e235762009-09-29 14:56:15 +0000226 int i;
Yinghai Lud4b278c2006-10-04 20:46:15 +0000227 for(i=0;i<4;i++) {
228 activate_spd_rom(&cpu[i]);
229 dump_smbus_registers();
230 }
231#endif
232
233#if 0
234 for(i=1;i<256;i<<=1) {
235 change_i2c_mux(i);
236 dump_smbus_registers();
237 }
238#endif
239
240 memreset_setup();
241
242 //do we need apci timer, tsc...., only debug need it for better output
243 /* all ap stopped? */
244// init_timer(); // Need to use TMICT to synconize FID/VID
245
246 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
247
248#if 0
249 print_pci_devices();
250#endif
251
252#if 0
253// dump_pci_devices();
254 dump_pci_device_index_wait(PCI_DEV(0, 0x18, 2), 0x98);
255 dump_pci_device_index_wait(PCI_DEV(0, 0x19, 2), 0x98);
256#endif
257
258 post_cache_as_ram(); // bsp swtich stack to ram and copy sysinfo ram now
Yinghai Lud4b278c2006-10-04 20:46:15 +0000259}