blob: 470a7ee40a3c36e3301493d190729fe61f4afa36 [file] [log] [blame]
Yinghai Lud4b278c2006-10-04 20:46:15 +00001#define ASSEMBLY 1
Myles Watson1d6d45e2009-11-06 17:02:51 +00002#define __PRE_RAM__
Yinghai Lud4b278c2006-10-04 20:46:15 +00003
4#define RAMINIT_SYSINFO 1
5#define CACHE_AS_RAM_ADDRESS_DEBUG 0
6
7#define SET_NB_CFG_54 1
8
9//used by raminit
10#define QRANK_DIMM_SUPPORT 1
11
12//used by incoherent_ht
Yinghai Lud4b278c2006-10-04 20:46:15 +000013//#define K8_ALLOCATE_IO_RANGE 1
14
Yinghai Lud4b278c2006-10-04 20:46:15 +000015//used by init_cpus and fidvid
Yinghai Lu5f9624d2006-10-04 22:56:21 +000016#define K8_SET_FIDVID 0
Yinghai Lud4b278c2006-10-04 20:46:15 +000017//if we want to wait for core1 done before DQS training, set it to 0
18#define K8_SET_FIDVID_CORE0_ONLY 1
19
Stefan Reinauer08670622009-06-30 15:17:49 +000020#if CONFIG_K8_REV_F_SUPPORT == 1
Yinghai Lud4b278c2006-10-04 20:46:15 +000021#define K8_REV_F_SUPPORT_F0_F1_WORKAROUND 0
Yinghai Lu5f9624d2006-10-04 22:56:21 +000022#endif
Yinghai Lud4b278c2006-10-04 20:46:15 +000023
24#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000025#include <string.h>
Yinghai Lud4b278c2006-10-04 20:46:15 +000026#include <device/pci_def.h>
27#include <device/pci_ids.h>
28#include <arch/io.h>
29#include <device/pnp_def.h>
30#include <arch/romcc_io.h>
31#include <cpu/x86/lapic.h>
32#include "option_table.h"
33#include "pc80/mc146818rtc_early.c"
34
Marc Jones2080bd92008-09-29 22:59:23 +000035
Yinghai Lud4b278c2006-10-04 20:46:15 +000036#if 0
37static void post_code(uint8_t value) {
38#if 1
39 int i;
40 for(i=0;i<0x80000;i++) {
41 outb(value, 0x80);
42 }
43#endif
44}
45#endif
Stefan Reinauer08670622009-06-30 15:17:49 +000046#if CONFIG_USE_FAILOVER_IMAGE==0
Yinghai Lud4b278c2006-10-04 20:46:15 +000047#include "pc80/serial.c"
48#include "arch/i386/lib/console.c"
49#include <cpu/amd/model_fxx_rev.h>
50#include "southbridge/amd/amd8111/amd8111_early_smbus.c"
51#include "northbridge/amd/amdk8/raminit.h"
52#include "cpu/amd/model_fxx/apic_timer.c"
53#endif
54
55
56
57#include "cpu/x86/lapic/boot_cpu.c"
58#include "northbridge/amd/amdk8/reset_test.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +000059
Stefan Reinauer08670622009-06-30 15:17:49 +000060#if CONFIG_USE_FAILOVER_IMAGE==0
Yinghai Lu5f9624d2006-10-04 22:56:21 +000061#include "cpu/x86/bist.h"
Yinghai Lud4b278c2006-10-04 20:46:15 +000062
63#include "lib/delay.c"
64
Yinghai Lud4b278c2006-10-04 20:46:15 +000065#include "northbridge/amd/amdk8/debug.c"
66#include "cpu/amd/mtrr/amd_earlymtrr.c"
67#include "superio/winbond/w83627hf/w83627hf_early_serial.c"
68
69#include "northbridge/amd/amdk8/setup_resource_map.c"
70
71#define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
72
73#include "southbridge/amd/amd8111/amd8111_early_ctrl.c"
74
75static void memreset_setup(void)
76{
77 //GPIO on amd8111 to enable MEMRST ????
78 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=1
79 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 17);
80}
81
82static void memreset(int controllers, const struct mem_controller *ctrl)
83{
84}
85
86static inline void activate_spd_rom(const struct mem_controller *ctrl)
87{
88#define SMBUS_HUB 0x18
89 int ret,i;
90 unsigned device=(ctrl->channel0[0])>>8;
91 /* the very first write always get COL_STS=1 and ABRT_STS=1, so try another time*/
92 i=2;
93 do {
94 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
95 } while ((ret!=0) && (i-->0));
96
97 smbus_write_byte(SMBUS_HUB, 0x03, 0);
98}
99#if 0
100static inline void change_i2c_mux(unsigned device)
101{
102#define SMBUS_HUB 0x18
103 int ret, i;
104 print_debug("change_i2c_mux i="); print_debug_hex8(device); print_debug("\r\n");
105 i=2;
106 do {
107 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
108 print_debug("change_i2c_mux 1 ret="); print_debug_hex32(ret); print_debug("\r\n");
109 } while ((ret!=0) && (i-->0));
110 ret = smbus_write_byte(SMBUS_HUB, 0x03, 0);
111 print_debug("change_i2c_mux 2 ret="); print_debug_hex32(ret); print_debug("\r\n");
112}
113#endif
114
115static inline int spd_read_byte(unsigned device, unsigned address)
116{
117 return smbus_read_byte(device, address);
118}
119
Yinghai Lu5f9624d2006-10-04 22:56:21 +0000120#include "northbridge/amd/amdk8/amdk8.h"
Yinghai Lud4b278c2006-10-04 20:46:15 +0000121#include "northbridge/amd/amdk8/coherent_ht.c"
122
123#include "northbridge/amd/amdk8/incoherent_ht.c"
124
Myles Watson17257032009-06-04 20:18:42 +0000125#include "northbridge/amd/amdk8/raminit_f.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +0000126
Stefan Reinauerc13093b2009-09-23 18:51:03 +0000127#include "lib/generic_sdram.c"
Yinghai Lud4b278c2006-10-04 20:46:15 +0000128
129 /* tyan does not want the default */
130#include "resourcemap.c"
131
132#include "cpu/amd/dualcore/dualcore.c"
133
134#define RC0 ((1<<0)<<8)
135#define RC1 ((1<<1)<<8)
136#define RC2 ((1<<2)<<8)
137#define RC3 ((1<<3)<<8)
138
139#define DIMM0 0x50
140#define DIMM1 0x51
141#define DIMM2 0x52
142#define DIMM3 0x53
143#define DIMM4 0x54
144#define DIMM5 0x55
145#define DIMM6 0x56
146#define DIMM7 0x57
147
148
149#include "cpu/amd/car/copy_and_run.c"
150#include "cpu/amd/car/post_cache_as_ram.c"
151
152#include "cpu/amd/model_fxx/init_cpus.c"
153
154#include "cpu/amd/model_fxx/fidvid.c"
155#endif
156
Yinghai Lud4b278c2006-10-04 20:46:15 +0000157#include "southbridge/amd/amd8111/amd8111_enable_rom.c"
158#include "northbridge/amd/amdk8/early_ht.c"
159
Stefan Reinauer08670622009-06-30 15:17:49 +0000160#if CONFIG_USE_FAILOVER_IMAGE==0
Yinghai Lud4b278c2006-10-04 20:46:15 +0000161
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000162void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000163{
164 static const uint16_t spd_addr[] = {
165 //first node
166 RC0|DIMM0, RC0|DIMM2, 0, 0,
167 RC0|DIMM1, RC0|DIMM3, 0, 0,
168#if CONFIG_MAX_PHYSICAL_CPUS > 1
169 //second node
170 RC1|DIMM0, RC1|DIMM2, RC1|DIMM4, RC1|DIMM6,
171 RC1|DIMM1, RC1|DIMM3, RC1|DIMM5, RC1|DIMM7,
172#endif
173#if CONFIG_MAX_PHYSICAL_CPUS > 2
174 // third node
175 RC2|DIMM0, RC2|DIMM2, 0, 0,
176 RC2|DIMM1, RC2|DIMM3, 0, 0,
177 // four node
178 RC3|DIMM0, RC3|DIMM2, RC3|DIMM4, RC3|DIMM6,
179 RC3|DIMM1, RC3|DIMM3, RC3|DIMM5, RC3|DIMM7,
180#endif
181
182 };
183
Myles Watson6e235762009-09-29 14:56:15 +0000184 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 +0000185
Myles Watson6e235762009-09-29 14:56:15 +0000186 int needs_reset;
Yinghai Lud4b278c2006-10-04 20:46:15 +0000187 unsigned bsp_apicid = 0;
Myles Watson6e235762009-09-29 14:56:15 +0000188#if K8_SET_FIDVID == 1
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000189 struct cpuid_result cpuid1;
Myles Watson6e235762009-09-29 14:56:15 +0000190#endif
Yinghai Lud4b278c2006-10-04 20:46:15 +0000191
Patrick Georgi2bd91002010-03-18 16:46:50 +0000192 if (!cpu_init_detectedx && boot_cpu()) {
Patrick Georgice6fb1e2010-03-17 22:44:39 +0000193 /* Nothing special needs to be done to find bus 0 */
194 /* Allow the HT devices to be found */
195
196 enumerate_ht_chain();
197
198 /* Setup the rom access for 4M */
199 amd8111_enable_rom();
200 }
201
Yinghai Lud4b278c2006-10-04 20:46:15 +0000202 if (bist == 0) {
Yinghai Lud4b278c2006-10-04 20:46:15 +0000203 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
204 }
205
206// post_code(0x32);
207
Stefan Reinauer08670622009-06-30 15:17:49 +0000208 w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000209 uart_init();
210 console_init();
211
Stefan Reinauer08670622009-06-30 15:17:49 +0000212// dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x200, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000213
214 /* Halt if there was a built in self test failure */
215 report_bist_failure(bist);
216
217 print_debug("*sysinfo range: ["); print_debug_hex32(sysinfo); print_debug(","); print_debug_hex32((unsigned long)sysinfo+sizeof(struct sys_info)); print_debug(")\r\n");
218
Yinghai Lu5f9624d2006-10-04 22:56:21 +0000219 setup_mb_resource_map();
Yinghai Lud4b278c2006-10-04 20:46:15 +0000220#if 0
221 dump_pci_device(PCI_DEV(0, 0x18, 0));
222 dump_pci_device(PCI_DEV(0, 0x19, 0));
223#endif
224
225 print_debug("bsp_apicid="); print_debug_hex8(bsp_apicid); print_debug("\r\n");
226
Stefan Reinauer08670622009-06-30 15:17:49 +0000227#if CONFIG_MEM_TRAIN_SEQ == 1
Yinghai Lud4b278c2006-10-04 20:46:15 +0000228 set_sysinfo_in_ram(0); // in BSP so could hold all ap until sysinfo is in ram
229#endif
230 setup_coherent_ht_domain(); // routing table and start other core0
231
232 wait_all_core0_started();
233#if CONFIG_LOGICAL_CPUS==1
234 // It is said that we should start core1 after all core0 launched
235 /* becase optimize_link_coherent_ht is moved out from setup_coherent_ht_domain,
236 * So here need to make sure last core0 is started, esp for two way system,
237 * (there may be apic id conflicts in that case)
238 */
239 start_other_cores();
240 wait_all_other_cores_started(bsp_apicid);
241#endif
242
243 /* it will set up chains and store link pair for optimization later */
244 ht_setup_chains_x(sysinfo); // it will init sblnk and sbbusn, nodes, sbdn
245
246#if 0
247 //it your CPU min fid is 1G, you can change HT to 1G and FID to max one time.
248 needs_reset = optimize_link_coherent_ht();
249 needs_reset |= optimize_link_incoherent_ht(sysinfo);
250#endif
251
252#if K8_SET_FIDVID == 1
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000253 /* Check to see if processor is capable of changing FIDVID */
254 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
255 cpuid1 = cpuid(0x80000007);
256 if( (cpuid1.edx & 0x6) == 0x6 ) {
Yinghai Lud4b278c2006-10-04 20:46:15 +0000257
258 {
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000259 /* Read FIDVID_STATUS */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000260 msr_t msr;
261 msr=rdmsr(0xc0010042);
262 print_debug("begin msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\r\n");
263
264 }
265
266 enable_fid_change();
267
268 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
269
270 init_fidvid_bsp(bsp_apicid);
271
272 // show final fid and vid
273 {
274 msr_t msr;
275 msr=rdmsr(0xc0010042);
276 print_debug("end msr fid, vid "); print_debug_hex32( msr.hi ); print_debug_hex32(msr.lo); print_debug("\r\n");
277
278 }
Dan Lykowski6ef8e0f2009-01-12 16:16:08 +0000279
280 } else {
281 print_debug("Changing FIDVID not supported\n");
282 }
283
Yinghai Lud4b278c2006-10-04 20:46:15 +0000284#endif
285
286#if 1
287 needs_reset = optimize_link_coherent_ht();
288 needs_reset |= optimize_link_incoherent_ht(sysinfo);
289
290 // fidvid change will issue one LDTSTOP and the HT change will be effective too
291 if (needs_reset) {
292 print_info("ht reset -\r\n");
293 soft_reset_x(sysinfo->sbbusn, sysinfo->sbdn);
294 }
295#endif
296 allow_all_aps_stop(bsp_apicid);
297
Yinghai Lud4b278c2006-10-04 20:46:15 +0000298 //It's the time to set ctrl in sysinfo now;
299 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000300
301 enable_smbus();
302
303#if 0
Myles Watson6e235762009-09-29 14:56:15 +0000304 int i;
Yinghai Lud4b278c2006-10-04 20:46:15 +0000305 for(i=0;i<4;i++) {
306 activate_spd_rom(&cpu[i]);
307 dump_smbus_registers();
308 }
309#endif
310
311#if 0
312 for(i=1;i<256;i<<=1) {
313 change_i2c_mux(i);
314 dump_smbus_registers();
315 }
316#endif
317
318 memreset_setup();
319
320 //do we need apci timer, tsc...., only debug need it for better output
321 /* all ap stopped? */
322// init_timer(); // Need to use TMICT to synconize FID/VID
323
324 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
325
326#if 0
327 print_pci_devices();
328#endif
329
330#if 0
331// dump_pci_devices();
332 dump_pci_device_index_wait(PCI_DEV(0, 0x18, 2), 0x98);
333 dump_pci_device_index_wait(PCI_DEV(0, 0x19, 2), 0x98);
334#endif
335
336 post_cache_as_ram(); // bsp swtich stack to ram and copy sysinfo ram now
337
338}
339#endif