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
75 static inline void activate_spd_rom(const struct mem_controller *ctrl)
77 #define SMBUS_HUB 0x18
79 unsigned device=(ctrl->channel0[0])>>8;
82 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
83 } while ((ret!=0) && (i-->0));
85 smbus_write_byte(SMBUS_HUB, 0x03, 0);
88 static inline int spd_read_byte(unsigned device, unsigned address)
90 return smbus_read_byte(device, address);
93 #define K8_4RANK_DIMM_SUPPORT 1
95 #include "northbridge/amd/amdk8/raminit.c"
97 #define ENABLE_APIC_EXT_ID 1
98 #define APIC_ID_OFFSET 0x10
99 #define LIFT_BSP_APIC_ID 0
101 #define ENABLE_APIC_EXT_ID 0
103 #include "northbridge/amd/amdk8/coherent_ht.c"
104 #include "sdram/generic_sdram.c"
106 /* tyan does not want the default */
107 #include "resourcemap.c"
109 #if CONFIG_LOGICAL_CPUS==1
110 #define SET_NB_CFG_54 1
111 #include "cpu/amd/dualcore/dualcore.c"
119 #define TOTAL_CPUS (FIRST_CPU + SECOND_CPU + THIRD_CPU + FOURTH_CPU)
121 #define RC0 ((1<<2)<<8)
122 #define RC1 ((1<<1)<<8)
123 #define RC2 ((1<<4)<<8)
124 #define RC3 ((1<<3)<<8)
131 #include "cpu/amd/car/copy_and_run.c"
133 #if USE_FALLBACK_IMAGE == 1
135 #include "southbridge/amd/amd8111/amd8111_enable_rom.c"
136 #include "northbridge/amd/amdk8/early_ht.c"
138 void real_main(unsigned long bist);
140 void amd64_main(unsigned long bist)
142 #if CONFIG_LOGICAL_CPUS==1
143 struct node_core_id id;
147 /* Make cerain my local apic is useable */
150 #if CONFIG_LOGICAL_CPUS==1
151 id = get_node_core_id_x();
152 /* Is this a cpu only reset? */
153 if (cpu_init_detected(id.nodeid)) {
155 // nodeid = lapicid();
156 nodeid = get_node_id();
157 /* Is this a cpu only reset? */
158 if (cpu_init_detected(nodeid)) {
160 if (last_boot_normal()) {
167 /* Is this a secondary cpu? */
169 if (last_boot_normal()) {
176 /* Nothing special needs to be done to find bus 0 */
177 /* Allow the HT devices to be found */
179 enumerate_ht_chain();
181 /* Setup the ck804 */
182 amd8111_enable_rom();
184 /* Is this a deliberate reset by the bios */
185 if (bios_reset_detected() && last_boot_normal()) {
188 /* This is the primary cpu how should I boot? */
189 else if (do_normal_boot()) {
196 __asm__ volatile ("jmp __normal_image"
198 : "a" (bist) /* inputs */
202 //CPU reset will reset memtroller ???
203 asm volatile ("jmp __cpu_reset"
205 : "a"(bist) /* inputs */
212 void real_main(unsigned long bist)
214 void amd64_main(unsigned long bist)
217 static const struct mem_controller cpu[] = {
221 .f0 = PCI_DEV(0, 0x18, 0),
222 .f1 = PCI_DEV(0, 0x18, 1),
223 .f2 = PCI_DEV(0, 0x18, 2),
224 .f3 = PCI_DEV(0, 0x18, 3),
225 .channel0 = { RC0|DIMM0, RC0|DIMM2, 0, 0 },
226 .channel1 = { RC0|DIMM1, RC0|DIMM3, 0, 0 },
232 .f0 = PCI_DEV(0, 0x19, 0),
233 .f1 = PCI_DEV(0, 0x19, 1),
234 .f2 = PCI_DEV(0, 0x19, 2),
235 .f3 = PCI_DEV(0, 0x19, 3),
236 .channel0 = { RC1|DIMM0, RC1|DIMM2 , 0, 0 },
237 .channel1 = { RC1|DIMM1, RC1|DIMM3 , 0, 0 },
245 .f0 = PCI_DEV(0, 0x1a, 0),
246 .f1 = PCI_DEV(0, 0x1a, 1),
247 .f2 = PCI_DEV(0, 0x1a, 2),
248 .f3 = PCI_DEV(0, 0x1a, 3),
249 .channel0 = { RC2|DIMM0, RC2|DIMM2, 0, 0 },
250 .channel1 = { RC2|DIMM1, RC2|DIMM3, 0, 0 },
257 .f0 = PCI_DEV(0, 0x1b, 0),
258 .f1 = PCI_DEV(0, 0x1b, 1),
259 .f2 = PCI_DEV(0, 0x1b, 2),
260 .f3 = PCI_DEV(0, 0x1b, 3),
261 .channel0 = { RC3|DIMM0, RC3|DIMM2, 0, 0 },
262 .channel1 = { RC3|DIMM1, RC3|DIMM3, 0, 0 },
269 unsigned cpu_reset = 0;
272 #if CONFIG_LOGICAL_CPUS==1
273 struct node_core_id id;
277 /* Skip this if there was a built in self test failure */
278 // amd_early_mtrr_init(); # don't need, already done in cache_as_ram
280 #if CONFIG_LOGICAL_CPUS==1
281 set_apicid_cpuid_lo();
282 id = get_node_core_id_x(); // that is initid
283 #if ENABLE_APIC_EXT_ID == 1
285 enable_apic_ext_id(id.nodeid);
289 nodeid = get_node_id();
290 #if ENABLE_APIC_EXT_ID == 1
291 enable_apic_ext_id(nodeid);
299 #if CONFIG_LOGICAL_CPUS==1
300 #if ENABLE_APIC_EXT_ID == 1
301 #if LIFT_BSP_APIC_ID == 0
302 if( id.nodeid != 0 ) //all except cores in node0
304 lapic_write(LAPIC_ID, ( lapic_read(LAPIC_ID) | (APIC_ID_OFFSET<<24) ) );
307 if (cpu_init_detected(id.nodeid)) {
311 distinguish_cpu_resets(id.nodeid);
314 #if ENABLE_APIC_EXT_ID == 1
315 #if LIFT_BSP_APIC_ID == 0
318 lapic_write(LAPIC_ID, ( lapic_read(LAPIC_ID) | (APIC_ID_OFFSET<<24) ) ); // CPU apicid is from 0x10
321 if (cpu_init_detected(nodeid)) {
325 distinguish_cpu_resets(nodeid);
330 #if CONFIG_LOGICAL_CPUS==1
334 // We need stop the CACHE as RAM for this CPU too
335 #include "cpu/amd/car/cache_as_ram_post.c"
336 stop_this_cpu(); // it will stop all cores except core0 of cpu0
341 w83627hf_enable_serial(SERIAL_DEV, TTYS0_BASE);
345 dump_mem(DCACHE_RAM_BASE+DCACHE_RAM_SIZE-0x200, DCACHE_RAM_BASE+DCACHE_RAM_SIZE);
347 /* Halt if there was a built in self test failure */
348 report_bist_failure(bist);
350 setup_s4882_resource_map();
352 dump_pci_device(PCI_DEV(0, 0x18, 0));
353 dump_pci_device(PCI_DEV(0, 0x19, 0));
356 needs_reset = setup_coherent_ht_domain();
358 #if CONFIG_LOGICAL_CPUS==1
359 // It is said that we should start core1 after all core0 launched
362 needs_reset |= ht_setup_chains_x();
365 print_info("ht reset -\r\n");
372 sdram_initialize(sizeof(cpu)/sizeof(cpu[0]), cpu);
376 /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
383 printk_debug("v_esp=%08x\r\n", v_esp);
385 print_debug("v_esp="); print_debug_hex32(v_esp); print_debug("\r\n");
395 printk_debug("cpu_reset = %08x\r\n",cpu_reset);
397 print_debug("cpu_reset = "); print_debug_hex32(cpu_reset); print_debug("\r\n");
401 print_debug("Clearing initial memory region: ");
403 print_debug("No cache as ram now - ");
405 /* store cpu_reset to ebx */
412 #define CLEAR_FIRST_1M_RAM 1
413 #include "cpu/amd/car/cache_as_ram_post.c"
416 #undef CLEAR_FIRST_1M_RAM
417 #include "cpu/amd/car/cache_as_ram_post.c"
421 /* set new esp */ /* before _RAMBASE */
424 ::"a"( _RAMBASE - 4 )
428 unsigned new_cpu_reset;
430 /* get back cpu_reset from ebx */
433 :"=a" (new_cpu_reset)
436 print_debug("Use Ram as Stack now - "); /* but We can not go back any more, we lost old stack data in cache as ram*/
437 if(new_cpu_reset==0) {
438 print_debug("done\r\n");
445 printk_debug("new_cpu_reset = %08x\r\n", new_cpu_reset);
447 print_debug("new_cpu_reset = "); print_debug_hex32(new_cpu_reset); print_debug("\r\n");
449 /*copy and execute linuxbios_ram */
450 copy_and_run(new_cpu_reset);
451 /* We will not return */
455 print_debug("should not be here -\r\n");