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"
17 #include "northbridge/amd/amdk8/cpu_rev.c"
18 #define K8_HT_FREQ_1G_SUPPORT 0
19 #include "northbridge/amd/amdk8/incoherent_ht.c"
20 #include "southbridge/nvidia/ck804/ck804_early_smbus.c"
21 #include "northbridge/amd/amdk8/raminit.h"
22 #include "cpu/amd/model_fxx/apic_timer.c"
23 #include "lib/delay.c"
25 #if CONFIG_USE_INIT == 0
26 #include "lib/memcpy.c"
29 #include "cpu/x86/lapic/boot_cpu.c"
30 #include "northbridge/amd/amdk8/reset_test.c"
31 #include "northbridge/amd/amdk8/debug.c"
32 #include "superio/smsc/lpc47b397/lpc47b397_early_serial.c"
34 #include "cpu/amd/mtrr/amd_earlymtrr.c"
35 #include "cpu/x86/bist.h"
37 #include "superio/smsc/lpc47b397/lpc47b397_early_gpio.c"
39 #include "northbridge/amd/amdk8/setup_resource_map.c"
41 #define SERIAL_DEV PNP_DEV(0x2e, LPC47B397_SP1)
43 static void hard_reset(void)
52 static void soft_reset(void)
62 static void memreset_setup(void)
66 static void memreset(int controllers, const struct mem_controller *ctrl)
70 #define SUPERIO_GPIO_DEV PNP_DEV(0x2e, LPC47B397_RT)
72 #define SUPERIO_GPIO_IO_BASE 0x400
74 static void sio_gpio_setup(void){
80 /*Enable onboard scsi*/
81 lpc47b397_gpio_offset_out(SUPERIO_GPIO_IO_BASE, 0x2c, (1<<7)|(0<<2)|(0<<1)|(0<<0)); // GP21, offset 0x2c, DISABLE_SCSI_L
82 value = lpc47b397_gpio_offset_in(SUPERIO_GPIO_IO_BASE, 0x4c);
83 lpc47b397_gpio_offset_out(SUPERIO_GPIO_IO_BASE, 0x4c, (value|(1<<1)));
88 static inline void activate_spd_rom(const struct mem_controller *ctrl)
93 static inline int spd_read_byte(unsigned device, unsigned address)
95 return smbus_read_byte(device, address);
98 #define K8_4RANK_DIMM_SUPPORT 1
100 #include "northbridge/amd/amdk8/raminit.c"
102 #define ENABLE_APIC_EXT_ID 1
103 #define APIC_ID_OFFSET 0x10
104 #define LIFT_BSP_APIC_ID 0
106 #define ENABLE_APIC_EXT_ID 0
108 #include "northbridge/amd/amdk8/coherent_ht.c"
109 #include "sdram/generic_sdram.c"
111 /* tyan does not want the default */
112 #include "resourcemap.c"
114 #if CONFIG_LOGICAL_CPUS==1
115 #define SET_NB_CFG_54 1
116 #include "cpu/amd/dualcore/dualcore.c"
121 #define TOTAL_CPUS (FIRST_CPU + SECOND_CPU)
124 //#define CK804B_BUSN 0x80
125 #define CK804B_BUSN 0xc
126 #define CK804_USE_NIC 1
127 #define CK804_USE_ACI 1
129 #include "southbridge/nvidia/ck804/ck804_early_setup_ss.h"
131 //set GPIO to input mode
132 #define CK804_MB_SETUP \
133 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+ 5, ~(0xff),((0<<4)|(0<<2)|(0<<0)),/* M9,GPIO6, PCIXB2_PRSNT1_L*/ \
134 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+15, ~(0xff),((0<<4)|(0<<2)|(0<<0)),/* M8,GPIO16, PCIXB2_PRSNT2_L*/ \
135 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+44, ~(0xff),((0<<4)|(0<<2)|(0<<0)),/* P5,GPIO45, PCIXA_PRSNT1_L*/ \
136 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+ 7, ~(0xff),((0<<4)|(0<<2)|(0<<0)),/* M5,GPIO8, PCIXA_PRSNT2_L*/ \
137 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+16, ~(0xff),((0<<4)|(0<<2)|(0<<0)),/* K4,GPIO17, PCIXB_PRSNT1_L*/ \
138 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+45, ~(0xff),((0<<4)|(0<<2)|(0<<0)),/* P7,GPIO46, PCIXB_PRSNT2_L*/
140 #include "southbridge/nvidia/ck804/ck804_early_setup.c"
142 #include "cpu/amd/car/copy_and_run.c"
144 #if USE_FALLBACK_IMAGE == 1
146 #include "southbridge/nvidia/ck804/ck804_enable_rom.c"
147 #include "northbridge/amd/amdk8/early_ht.c"
150 static void sio_setup(void)
158 pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1, 0), 0xac, 0x047f0400);
160 byte = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b);
162 pci_write_config8(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b, byte);
164 dword = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0);
165 dword |= (1<<29)|(1<<0);
166 pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0, dword);
169 lpc47b397_enable_serial(SUPERIO_GPIO_DEV, SUPERIO_GPIO_IO_BASE);
171 value = lpc47b397_gpio_offset_in(SUPERIO_GPIO_IO_BASE, 0x77);
173 lpc47b397_gpio_offset_out(SUPERIO_GPIO_IO_BASE, 0x77, value);
178 void real_main(unsigned long bist);
180 void amd64_main(unsigned long bist)
182 #if CONFIG_LOGICAL_CPUS==1
183 struct node_core_id id;
187 /* Make cerain my local apic is useable */
190 #if CONFIG_LOGICAL_CPUS==1
191 id = get_node_core_id_x();
192 /* Is this a cpu only reset? */
193 if (cpu_init_detected(id.nodeid)) {
195 // nodeid = lapicid() & 0xf;
196 nodeid = get_node_id();
197 /* Is this a cpu only reset? */
198 if (cpu_init_detected(nodeid)) {
200 if (last_boot_normal()) {
207 /* Is this a secondary cpu? */
209 if (last_boot_normal()) {
216 /* Nothing special needs to be done to find bus 0 */
217 /* Allow the HT devices to be found */
219 enumerate_ht_chain();
223 /* Setup the ck804 */
226 /* Is this a deliberate reset by the bios */
227 if (bios_reset_detected() && last_boot_normal()) {
230 /* This is the primary cpu how should I boot? */
231 else if (do_normal_boot()) {
238 __asm__ volatile ("jmp __normal_image"
240 : "a" (bist) /* inputs */
244 //CPU reset will reset memtroller ???
245 asm volatile ("jmp __cpu_reset"
247 : "a"(bist) /* inputs */
254 void real_main(unsigned long bist)
256 void amd64_main(unsigned long bist)
259 static const struct mem_controller cpu[] = {
263 .f0 = PCI_DEV(0, 0x18, 0),
264 .f1 = PCI_DEV(0, 0x18, 1),
265 .f2 = PCI_DEV(0, 0x18, 2),
266 .f3 = PCI_DEV(0, 0x18, 3),
267 .channel0 = { (0xa<<3)|0, (0xa<<3)|2, 0, 0 },
268 .channel1 = { (0xa<<3)|1, (0xa<<3)|3, 0, 0 },
274 .f0 = PCI_DEV(0, 0x19, 0),
275 .f1 = PCI_DEV(0, 0x19, 1),
276 .f2 = PCI_DEV(0, 0x19, 2),
277 .f3 = PCI_DEV(0, 0x19, 3),
278 .channel0 = { (0xa<<3)|4, (0xa<<3)|6, 0, 0 },
279 .channel1 = { (0xa<<3)|5, (0xa<<3)|7, 0, 0 },
286 unsigned cpu_reset = 0;
289 #if CONFIG_LOGICAL_CPUS==1
290 struct node_core_id id;
294 /* Skip this if there was a built in self test failure */
295 // amd_early_mtrr_init(); # don't need, already done in cache_as_ram
297 #if CONFIG_LOGICAL_CPUS==1
298 set_apicid_cpuid_lo();
299 id = get_node_core_id_x(); // that is initid
300 #if ENABLE_APIC_EXT_ID == 1
302 enable_apic_ext_id(id.nodeid);
306 nodeid = get_node_id();
307 #if ENABLE_APIC_EXT_ID == 1
308 enable_apic_ext_id(nodeid);
317 #if CONFIG_LOGICAL_CPUS==1
318 #if ENABLE_APIC_EXT_ID == 1
319 #if LIFT_BSP_APIC_ID == 0
320 if( id.nodeid != 0 ) //all except cores in node0
322 lapic_write(LAPIC_ID, ( lapic_read(LAPIC_ID) | (APIC_ID_OFFSET<<24) ) );
325 if (cpu_init_detected(id.nodeid)) {
329 distinguish_cpu_resets(id.nodeid);
332 #if ENABLE_APIC_EXT_ID == 1
333 #if LIFT_BSP_APIC_ID == 0
336 lapic_write(LAPIC_ID, ( lapic_read(LAPIC_ID) | (APIC_ID_OFFSET<<24) ) ); // CPU apicid is from 0x10
339 if (cpu_init_detected(nodeid)) {
343 distinguish_cpu_resets(nodeid);
348 #if CONFIG_LOGICAL_CPUS==1
352 // We need stop the CACHE as RAM for this CPU too
353 #include "cpu/amd/car/cache_as_ram_post.c"
354 stop_this_cpu(); // it will stop all cores except core0 of cpu0
359 lpc47b397_enable_serial(SERIAL_DEV, TTYS0_BASE);
363 /* Halt if there was a built in self test failure */
364 report_bist_failure(bist);
366 setup_s2895_resource_map();
368 dump_pci_device(PCI_DEV(0, 0x18, 0));
369 dump_pci_device(PCI_DEV(0, 0x19, 0));
372 needs_reset = setup_coherent_ht_domain();
374 #if CONFIG_LOGICAL_CPUS==1
375 // It is said that we should start core1 after all core0 launched
379 #if CK804B_BUSN == 0x80
380 // You need to preset bus num in PCI_DEV(0, 0x18,1) 0xe0, 0xe4, 0xe8, 0xec
381 needs_reset |= ht_setup_chains(3);
383 // automatically set that for you, but you might meet tight space
384 // Bcause it has two Ck804, we need to set CK804B_BUSN to 0xc (ht_setup_chains_x will let second CK804 use that bus num.
385 // otherwise ck804_eary_setup can not work rightly.
386 needs_reset |= ht_setup_chains_x();
389 needs_reset |= ck804_early_setup_x();
392 print_info("ht reset -\r\n");
398 dump_spd_registers(&cpu[0]);
401 dump_smbus_registers();
405 sdram_initialize(sizeof(cpu)/sizeof(cpu[0]), cpu);
413 /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
420 printk_debug("v_esp=%08x\r\n", v_esp);
422 print_debug("v_esp="); print_debug_hex32(v_esp); print_debug("\r\n");
431 printk_debug("cpu_reset = %08x\r\n",cpu_reset);
433 print_debug("cpu_reset = "); print_debug_hex32(cpu_reset); print_debug("\r\n");
437 print_debug("Clearing initial memory region: ");
439 print_debug("No cache as ram now - ");
441 /* store cpu_reset to ebx */
448 #define CLEAR_FIRST_1M_RAM 1
449 #include "cpu/amd/car/cache_as_ram_post.c"
452 #undef CLEAR_FIRST_1M_RAM
453 #include "cpu/amd/car/cache_as_ram_post.c"
457 /* set new esp */ /* before _RAMBASE */
460 ::"a"( _RAMBASE - 4 )
464 unsigned new_cpu_reset;
466 /* get back cpu_reset from ebx */
469 :"=a" (new_cpu_reset)
472 /* We can not go back any more, we lost old stack data in cache as ram*/
473 if(new_cpu_reset==0) {
474 print_debug("Use Ram as Stack now - done\r\n");
477 print_debug("Use Ram as Stack now - \r\n");
480 printk_debug("new_cpu_reset = %08x\r\n", new_cpu_reset);
482 print_debug("new_cpu_reset = "); print_debug_hex32(new_cpu_reset); print_debug("\r\n");
485 /*copy and execute linuxbios_ram */
486 copy_and_run(new_cpu_reset);
487 /* We will not return */
491 print_err("should not be here -\r\n");