5 #include <device/pci_def.h>
7 #include <device/pnp_def.h>
8 #include <arch/romcc_io.h>
9 #include <cpu/x86/lapic.h>
10 #include "option_table.h"
11 #include "pc80/mc146818rtc_early.c"
12 #include "pc80/serial.c"
13 #include "arch/i386/lib/console.c"
14 #include "ram/ramtest.c"
16 #include "northbridge/amd/amdk8/cpu_rev.c"
17 #define K8_HT_FREQ_1G_SUPPORT 0
18 #include "northbridge/amd/amdk8/incoherent_ht.c"
19 #include "southbridge/nvidia/ck804/ck804_early_smbus.c"
20 #include "northbridge/amd/amdk8/raminit.h"
21 #include "cpu/amd/model_fxx/apic_timer.c"
22 #include "lib/delay.c"
24 #if CONFIG_USE_INIT == 0
25 #include "lib/memcpy.c"
28 #include "cpu/x86/lapic/boot_cpu.c"
29 #include "northbridge/amd/amdk8/reset_test.c"
30 #include "northbridge/amd/amdk8/debug.c"
31 #include "superio/winbond/w83627hf/w83627hf_early_serial.c"
33 #include "cpu/amd/mtrr/amd_earlymtrr.c"
34 #include "cpu/x86/bist.h"
36 #include "northbridge/amd/amdk8/setup_resource_map.c"
38 #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
40 static void hard_reset(void)
49 static void soft_reset(void)
59 static void memreset_setup(void)
63 static void memreset(int controllers, const struct mem_controller *ctrl)
67 static inline void activate_spd_rom(const struct mem_controller *ctrl)
72 static inline int spd_read_byte(unsigned device, unsigned address)
74 return smbus_read_byte(device, address);
77 #define K8_4RANK_DIMM_SUPPORT 1
79 #include "northbridge/amd/amdk8/raminit.c"
80 #include "northbridge/amd/amdk8/coherent_ht.c"
81 #include "sdram/generic_sdram.c"
83 /* tyan does not want the default */
84 #include "resourcemap.c"
86 #if CONFIG_LOGICAL_CPUS==1
87 #define SET_NB_CFG_54 1
88 #include "cpu/amd/dualcore/dualcore.c"
93 #define TOTAL_CPUS (FIRST_CPU + SECOND_CPU)
96 #include "southbridge/nvidia/ck804/ck804_early_setup_ss.h"
97 //set GPIO to input mode
98 #define CK804_MB_SETUP \
99 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+15, ~(0xff), ((0<<4)|(0<<2)|(0<<0)),/* M8,GPIO16, PCIXA_PRSNT2_L*/ \
100 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+44, ~(0xff), ((0<<4)|(0<<2)|(0<<0)),/* P5,GPIO45, PCIXA_PRSNT1_L*/ \
101 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+16, ~(0xff), ((0<<4)|(0<<2)|(0<<0)),/* K4,GPIO17, PCIXB_PRSNT1_L*/ \
102 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+45, ~(0xff), ((0<<4)|(0<<2)|(0<<0)),/* P7,GPIO46, PCIXB_PRSNT2_L*/ \
104 #include "southbridge/nvidia/ck804/ck804_early_setup.c"
106 #include "cpu/amd/car/copy_and_run.c"
108 #if USE_FALLBACK_IMAGE == 1
110 #include "southbridge/nvidia/ck804/ck804_enable_rom.c"
111 #include "northbridge/amd/amdk8/early_ht.c"
113 static void sio_setup(void)
120 byte = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b);
122 pci_write_config8(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b, byte);
124 dword = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0);
126 pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0, dword);
130 void real_main(unsigned long bist);
132 void amd64_main(unsigned long bist)
134 #if CONFIG_LOGICAL_CPUS==1
135 struct node_core_id id;
139 /* Make cerain my local apic is useable */
142 #if CONFIG_LOGICAL_CPUS==1
143 id = get_node_core_id_x();
144 /* Is this a cpu only reset? */
145 if (cpu_init_detected(id.nodeid)) {
147 // nodeid = lapicid() & 0xf;
148 nodeid = get_node_id();
149 /* Is this a cpu only reset? */
150 if (cpu_init_detected(nodeid)) {
152 if (last_boot_normal()) {
159 /* Is this a secondary cpu? */
161 if (last_boot_normal()) {
168 /* Nothing special needs to be done to find bus 0 */
169 /* Allow the HT devices to be found */
171 enumerate_ht_chain();
175 /* Setup the ck804 */
178 /* Is this a deliberate reset by the bios */
179 if (bios_reset_detected() && last_boot_normal()) {
182 /* This is the primary cpu how should I boot? */
183 else if (do_normal_boot()) {
190 __asm__ volatile ("jmp __normal_image"
192 : "a" (bist) /* inputs */
196 //CPU reset will reset memtroller ???
197 asm volatile ("jmp __cpu_reset"
199 : "a"(bist) /* inputs */
206 void real_main(unsigned long bist)
208 void amd64_main(unsigned long bist)
211 static const struct mem_controller cpu[] = {
215 .f0 = PCI_DEV(0, 0x18, 0),
216 .f1 = PCI_DEV(0, 0x18, 1),
217 .f2 = PCI_DEV(0, 0x18, 2),
218 .f3 = PCI_DEV(0, 0x18, 3),
219 .channel0 = { (0xa<<3)|0, (0xa<<3)|2, 0, 0 },
220 .channel1 = { (0xa<<3)|1, (0xa<<3)|3, 0, 0 },
226 .f0 = PCI_DEV(0, 0x19, 0),
227 .f1 = PCI_DEV(0, 0x19, 1),
228 .f2 = PCI_DEV(0, 0x19, 2),
229 .f3 = PCI_DEV(0, 0x19, 3),
230 .channel0 = { (0xa<<3)|4, (0xa<<3)|6, 0, 0 },
231 .channel1 = { (0xa<<3)|5, (0xa<<3)|7, 0, 0 },
237 unsigned cpu_reset = 0;
240 #if CONFIG_LOGICAL_CPUS==1
241 struct node_core_id id;
245 /* Skip this if there was a built in self test failure */
246 // amd_early_mtrr_init(); # don't need, already done in cache_as_ram
248 #if CONFIG_LOGICAL_CPUS==1
249 set_apicid_cpuid_lo();
250 id = get_node_core_id_x(); // that is initid
252 nodeid = get_node_id();
258 #if CONFIG_LOGICAL_CPUS==1
260 if (cpu_init_detected(id.nodeid)) {
264 distinguish_cpu_resets(id.nodeid);
267 if (cpu_init_detected(nodeid)) {
271 distinguish_cpu_resets(nodeid);
276 #if CONFIG_LOGICAL_CPUS==1
280 // We need stop the CACHE as RAM for this CPU too
281 #include "cpu/amd/car/cache_as_ram_post.c"
282 stop_this_cpu(); // it will stop all cores except core0 of cpu0
287 init_timer(); // only do it it first CPU
290 w83627hf_enable_serial(SERIAL_DEV, TTYS0_BASE);
294 /* Halt if there was a built in self test failure */
295 report_bist_failure(bist);
297 setup_s2892_resource_map();
299 dump_pci_device(PCI_DEV(0, 0x18, 0));
300 dump_pci_device(PCI_DEV(0, 0x19, 0));
303 needs_reset = setup_coherent_ht_domain();
305 #if CONFIG_LOGICAL_CPUS==1
306 // It is said that we should start core1 after all core0 launched
309 needs_reset |= ht_setup_chains_x();
311 needs_reset |= ck804_early_setup_x();
314 print_info("ht reset -\r\n");
320 dump_spd_registers(&cpu[0]);
323 dump_smbus_registers();
327 sdram_initialize(sizeof(cpu)/sizeof(cpu[0]), cpu);
335 /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
342 printk_debug("v_esp=%08x\r\n", v_esp);
344 print_debug("v_esp="); print_debug_hex32(v_esp); print_debug("\r\n");
353 printk_debug("cpu_reset = %08x\r\n",cpu_reset);
355 print_debug("cpu_reset = "); print_debug_hex32(cpu_reset); print_debug("\r\n");
359 print_debug("Clearing initial memory region: ");
361 print_debug("No cache as ram now - ");
363 /* store cpu_reset to ebx */
370 #define CLEAR_FIRST_1M_RAM 1
371 #include "cpu/amd/car/cache_as_ram_post.c"
374 #undef CLEAR_FIRST_1M_RAM
375 #include "cpu/amd/car/cache_as_ram_post.c"
379 /* set new esp */ /* before _RAMBASE */
382 ::"a"( _RAMBASE - 4 )
386 unsigned new_cpu_reset;
388 /* get back cpu_reset from ebx */
391 :"=a" (new_cpu_reset)
394 /* We can not go back any more, we lost old stack data in cache as ram*/
395 if(new_cpu_reset==0) {
396 print_debug("Use Ram as Stack now - done\r\n");
399 print_debug("Use Ram as Stack now - \r\n");
402 printk_debug("new_cpu_reset = %08x\r\n", new_cpu_reset);
404 print_debug("new_cpu_reset = "); print_debug_hex32(new_cpu_reset); print_debug("\r\n");
407 /*copy and execute linuxbios_ram */
408 copy_and_run(new_cpu_reset);
409 /* We will not return */
413 print_debug("should not be here -\r\n");