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/amd/amd8111/amd8111_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)
45 pci_write_config8(PCI_DEV(0, 0x04, 3), 0x41, 0xf1);
50 static void soft_reset(void)
53 pci_write_config8(PCI_DEV(0, 0x04, 0), 0x47, 1);
56 static void memreset_setup(void)
58 if (is_cpu_pre_c0()) {
59 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=0
62 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=1
64 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 17);
67 static void memreset(int controllers, const struct mem_controller *ctrl)
69 if (is_cpu_pre_c0()) {
71 outb((0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 17); //REVB_MEMRST_L=1
76 static inline void activate_spd_rom(const struct mem_controller *ctrl)
81 static inline int spd_read_byte(unsigned device, unsigned address)
83 return smbus_read_byte(device, address);
86 #define K8_4RANK_DIMM_SUPPORT 1
88 #include "northbridge/amd/amdk8/raminit.c"
89 #include "resourcemap.c"
90 #include "northbridge/amd/amdk8/coherent_ht.c"
91 #include "sdram/generic_sdram.c"
93 #if CONFIG_LOGICAL_CPUS==1
94 #define SET_NB_CFG_54 1
95 #include "cpu/amd/dualcore/dualcore.c"
100 #define TOTAL_CPUS (FIRST_CPU + SECOND_CPU)
102 #include "cpu/amd/car/copy_and_run.c"
104 #if USE_FALLBACK_IMAGE == 1
106 #include "southbridge/amd/amd8111/amd8111_enable_rom.c"
107 #include "northbridge/amd/amdk8/early_ht.c"
109 void real_main(unsigned long bist);
111 void amd64_main(unsigned long bist)
113 #if CONFIG_LOGICAL_CPUS==1
114 struct node_core_id id;
118 /* Make cerain my local apic is useable */
121 #if CONFIG_LOGICAL_CPUS==1
122 id = get_node_core_id_x();
123 /* Is this a cpu only reset? */
124 if (cpu_init_detected(id.nodeid)) {
126 // nodeid = lapicid();
127 nodeid = get_node_id();
128 /* Is this a cpu only reset? */
129 if (cpu_init_detected(nodeid)) {
131 if (last_boot_normal()) {
138 /* Is this a secondary cpu? */
141 if (last_boot_normal()) {
148 /* Nothing special needs to be done to find bus 0 */
149 /* Allow the HT devices to be found */
151 enumerate_ht_chain();
153 /* Setup the ck804 */
154 amd8111_enable_rom();
156 /* Is this a deliberate reset by the bios */
158 if (bios_reset_detected() && last_boot_normal()) {
161 /* This is the primary cpu how should I boot? */
162 else if (do_normal_boot()) {
170 __asm__ volatile ("jmp __normal_image"
172 : "a" (bist) /* inputs */
177 //CPU reset will reset memtroller ???
178 asm volatile ("jmp __cpu_reset"
180 : "a"(bist) /* inputs */
188 void real_main(unsigned long bist)
190 void amd64_main(unsigned long bist)
193 static const struct mem_controller cpu[] = {
197 .f0 = PCI_DEV(0, 0x18, 0),
198 .f1 = PCI_DEV(0, 0x18, 1),
199 .f2 = PCI_DEV(0, 0x18, 2),
200 .f3 = PCI_DEV(0, 0x18, 3),
201 .channel0 = { (0xa<<3)|0, (0xa<<3)|2, 0, 0 },
202 .channel1 = { (0xa<<3)|1, (0xa<<3)|3, 0, 0 },
208 .f0 = PCI_DEV(0, 0x19, 0),
209 .f1 = PCI_DEV(0, 0x19, 1),
210 .f2 = PCI_DEV(0, 0x19, 2),
211 .f3 = PCI_DEV(0, 0x19, 3),
212 .channel0 = { (0xa<<3)|4, (0xa<<3)|6, 0, 0 },
213 .channel1 = { (0xa<<3)|5, (0xa<<3)|7, 0, 0 },
219 unsigned cpu_reset = 0;
222 #if CONFIG_LOGICAL_CPUS==1
223 struct node_core_id id;
227 /* Skip this if there was a built in self test failure */
228 // amd_early_mtrr_init(); # don't need, already done in cache_as_ram
230 #if CONFIG_LOGICAL_CPUS==1
231 set_apicid_cpuid_lo();
232 id = get_node_core_id_x(); // that is initid
234 nodeid = get_node_id();
241 #if CONFIG_LOGICAL_CPUS==1
243 if (cpu_init_detected(id.nodeid)) {
247 distinguish_cpu_resets(id.nodeid);
250 if (cpu_init_detected(nodeid)) {
254 distinguish_cpu_resets(nodeid);
259 #if CONFIG_LOGICAL_CPUS==1
263 // We need stop the CACHE as RAM for this CPU too
264 #include "cpu/amd/car/cache_as_ram_post.c"
265 stop_this_cpu(); // it will stop all cores except core0 of cpu0
270 w83627hf_enable_serial(SERIAL_DEV, TTYS0_BASE);
274 /* Halt if there was a built in self test failure */
275 report_bist_failure(bist);
277 setup_s2881_resource_map();
279 dump_pci_device(PCI_DEV(0, 0x18, 0));
280 dump_pci_device(PCI_DEV(0, 0x19, 0));
283 needs_reset = setup_coherent_ht_domain();
285 #if CONFIG_LOGICAL_CPUS==1
289 needs_reset |= ht_setup_chains_x();
292 print_info("ht reset -\r\n");
298 dump_spd_registers(&cpu[0]);
301 dump_smbus_registers();
305 sdram_initialize(sizeof(cpu)/sizeof(cpu[0]), cpu);
313 /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
320 printk_debug("v_esp=%08x\r\n", v_esp);
322 print_debug("v_esp="); print_debug_hex32(v_esp); print_debug("\r\n");
331 printk_debug("cpu_reset = %08x\r\n",cpu_reset);
333 print_debug("cpu_reset = "); print_debug_hex32(cpu_reset); print_debug("\r\n");
337 print_debug("Clearing initial memory region: ");
339 print_debug("No cache as ram now - ");
341 /* store cpu_reset to ebx */
348 #define CLEAR_FIRST_1M_RAM 1
349 #include "cpu/amd/car/cache_as_ram_post.c"
352 #undef CLEAR_FIRST_1M_RAM
353 #include "cpu/amd/car/cache_as_ram_post.c"
357 /* set new esp */ /* before _RAMBASE */
360 ::"a"( (DCACHE_RAM_BASE + DCACHE_RAM_SIZE)- _RAMBASE )
364 unsigned new_cpu_reset;
366 /* get back cpu_reset from ebx */
369 :"=a" (new_cpu_reset)
372 print_debug("Use Ram as Stack now - "); /* but We can not go back any more, we lost old stack data in cache as ram*/
373 if(new_cpu_reset==0) {
374 print_debug("done\r\n");
381 printk_debug("new_cpu_reset = %08x\r\n", new_cpu_reset);
383 print_debug("new_cpu_reset = "); print_debug_hex32(new_cpu_reset); print_debug("\r\n");
385 /*copy and execute linuxbios_ram */
386 copy_and_run(new_cpu_reset);
387 /* We will not return */
391 print_debug("should not be here -\r\n");