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 1
18 #define K8_ALLOCATE_IO_RANGE 1
19 //#define K8_SCAN_PCI_BUS 1
20 #include "northbridge/amd/amdk8/incoherent_ht.c"
21 #include "southbridge/nvidia/ck804/ck804_early_smbus.c"
22 #include "northbridge/amd/amdk8/raminit.h"
23 #include "cpu/amd/model_fxx/apic_timer.c"
24 #include "lib/delay.c"
26 #if CONFIG_USE_INIT == 0
27 #include "lib/memcpy.c"
30 #include "cpu/x86/lapic/boot_cpu.c"
31 #include "northbridge/amd/amdk8/reset_test.c"
32 #include "northbridge/amd/amdk8/debug.c"
33 #include "superio/smsc/lpc47b397/lpc47b397_early_serial.c"
35 #include "cpu/amd/mtrr/amd_earlymtrr.c"
36 #include "cpu/x86/bist.h"
38 #include "superio/smsc/lpc47b397/lpc47b397_early_gpio.c"
40 #include "northbridge/amd/amdk8/setup_resource_map.c"
42 #define SERIAL_DEV PNP_DEV(0x2e, LPC47B397_SP1)
44 static void hard_reset(void)
53 static void soft_reset(void)
63 static void memreset_setup(void)
67 static void memreset(int controllers, const struct mem_controller *ctrl)
71 #define SUPERIO_GPIO_DEV PNP_DEV(0x2e, LPC47B397_RT)
73 #define SUPERIO_GPIO_IO_BASE 0x400
75 static void sio_gpio_setup(void){
79 // lpc47b397_enable_serial(SUPERIO_GPIO_DEV, SUPERIO_GPIO_IO_BASE); // Already enable in failover.c
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)));
87 static inline void activate_spd_rom(const struct mem_controller *ctrl)
92 static inline int spd_read_byte(unsigned device, unsigned address)
94 return smbus_read_byte(device, address);
97 #define K8_4RANK_DIMM_SUPPORT 1
99 #include "northbridge/amd/amdk8/raminit.c"
101 #define ENABLE_APIC_EXT_ID 1
102 #define APIC_ID_OFFSET 0x10
103 #define LIFT_BSP_APIC_ID 0
105 #define ENABLE_APIC_EXT_ID 0
107 #include "northbridge/amd/amdk8/coherent_ht.c"
108 #include "sdram/generic_sdram.c"
110 /* tyan does not want the default */
111 #include "resourcemap.c"
113 #if CONFIG_LOGICAL_CPUS==1
114 #define SET_NB_CFG_54 1
115 #include "cpu/amd/dualcore/dualcore.c"
117 #include "cpu/amd/model_fxx/node_id.c"
122 #define TOTAL_CPUS (FIRST_CPU + SECOND_CPU)
125 #define CK804B_BUSN 0x80
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 /* LPC Variable Range Decode 1 0x400-0x47f */
159 /* to make sure lpc47b397 gpio on device work */
160 pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1, 0), 0xac, 0x047f0400);
162 /* subject decoding*/
163 byte = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b);
165 pci_write_config8(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b, byte);
167 /* LPC Positive Decode 0 */
168 dword = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0);
169 /*decode VAR1, serial 0 */
170 dword |= (1<<29)|(1<<0);
171 pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0, dword);
174 lpc47b397_enable_serial(SUPERIO_GPIO_DEV, SUPERIO_GPIO_IO_BASE);
176 value = lpc47b397_gpio_offset_in(SUPERIO_GPIO_IO_BASE, 0x77);
178 lpc47b397_gpio_offset_out(SUPERIO_GPIO_IO_BASE, 0x77, value);
183 void real_main(unsigned long bist);
185 void amd64_main(unsigned long bist)
187 #if CONFIG_LOGICAL_CPUS==1
188 struct node_core_id id;
192 /* Make cerain my local apic is useable */
195 #if CONFIG_LOGICAL_CPUS==1
196 id = get_node_core_id_x();
197 /* Is this a cpu only reset? */
198 if (cpu_init_detected(id.nodeid)) {
200 // nodeid = lapicid() & 0xf;
201 nodeid = get_node_id();
202 /* Is this a cpu only reset? */
203 if (cpu_init_detected(nodeid)) {
205 if (last_boot_normal()) {
212 /* Is this a secondary cpu? */
214 if (last_boot_normal()) {
221 /* Nothing special needs to be done to find bus 0 */
222 /* Allow the HT devices to be found */
224 enumerate_ht_chain();
228 /* Setup the ck804 */
231 /* Is this a deliberate reset by the bios */
232 if (bios_reset_detected() && last_boot_normal()) {
235 /* This is the primary cpu how should I boot? */
236 else if (do_normal_boot()) {
243 __asm__ volatile ("jmp __normal_image"
245 : "a" (bist) /* inputs */
249 //CPU reset will reset memtroller ???
250 asm volatile ("jmp __cpu_reset"
252 : "a"(bist) /* inputs */
259 void real_main(unsigned long bist)
261 void amd64_main(unsigned long bist)
264 static const struct mem_controller cpu[] = {
268 .f0 = PCI_DEV(0, 0x18, 0),
269 .f1 = PCI_DEV(0, 0x18, 1),
270 .f2 = PCI_DEV(0, 0x18, 2),
271 .f3 = PCI_DEV(0, 0x18, 3),
272 .channel0 = { (0xa<<3)|0, (0xa<<3)|2, 0, 0 },
273 .channel1 = { (0xa<<3)|1, (0xa<<3)|3, 0, 0 },
279 .f0 = PCI_DEV(0, 0x19, 0),
280 .f1 = PCI_DEV(0, 0x19, 1),
281 .f2 = PCI_DEV(0, 0x19, 2),
282 .f3 = PCI_DEV(0, 0x19, 3),
283 .channel0 = { (0xa<<3)|4, (0xa<<3)|6, 0, 0 },
284 .channel1 = { (0xa<<3)|5, (0xa<<3)|7, 0, 0 },
291 unsigned cpu_reset = 0;
294 #if CONFIG_LOGICAL_CPUS==1
295 struct node_core_id id;
299 /* Skip this if there was a built in self test failure */
300 // amd_early_mtrr_init(); # don't need, already done in cache_as_ram
302 #if CONFIG_LOGICAL_CPUS==1
303 set_apicid_cpuid_lo();
304 id = get_node_core_id_x(); // that is initid
305 #if ENABLE_APIC_EXT_ID == 1
307 enable_apic_ext_id(id.nodeid);
311 nodeid = get_node_id();
312 #if ENABLE_APIC_EXT_ID == 1
313 enable_apic_ext_id(nodeid);
322 #if CONFIG_LOGICAL_CPUS==1
323 #if ENABLE_APIC_EXT_ID == 1
324 #if LIFT_BSP_APIC_ID == 0
325 if( id.nodeid != 0 ) //all except cores in node0
327 lapic_write(LAPIC_ID, ( lapic_read(LAPIC_ID) | (APIC_ID_OFFSET<<24) ) );
330 if (cpu_init_detected(id.nodeid)) {
331 // __asm__ volatile ("jmp __cpu_reset");
335 distinguish_cpu_resets(id.nodeid);
336 // start_other_core(id.nodeid);
339 #if ENABLE_APIC_EXT_ID == 1
340 #if LIFT_BSP_APIC_ID == 0
343 lapic_write(LAPIC_ID, ( lapic_read(LAPIC_ID) | (APIC_ID_OFFSET<<24) ) ); // CPU apicid is from 0x10
346 if (cpu_init_detected(nodeid)) {
347 // __asm__ volatile ("jmp __cpu_reset");
351 distinguish_cpu_resets(nodeid);
356 #if CONFIG_LOGICAL_CPUS==1
360 // We need stop the CACHE as RAM for this CPU too
361 #include "cpu/amd/car/cache_as_ram_post.c"
362 stop_this_cpu(); // it will stop all cores except core0 of cpu0
366 init_timer(); // only do it it first CPU
369 lpc47b397_enable_serial(SERIAL_DEV, TTYS0_BASE);
373 /* Halt if there was a built in self test failure */
374 report_bist_failure(bist);
376 setup_s2895_resource_map();
378 needs_reset = setup_coherent_ht_domain();
380 #if CONFIG_LOGICAL_CPUS==1
381 // It is said that we should start core1 after all core0 launched
385 needs_reset |= ht_setup_chains_x();
387 needs_reset |= ck804_early_setup_x();
390 print_info("ht reset -\r\n");
397 sdram_initialize(sizeof(cpu)/sizeof(cpu[0]), cpu);
401 /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
408 printk_debug("v_esp=%08x\r\n", v_esp);
410 print_debug("v_esp="); print_debug_hex32(v_esp); print_debug("\r\n");
420 printk_debug("cpu_reset = %08x\r\n",cpu_reset);
422 print_debug("cpu_reset = "); print_debug_hex32(cpu_reset); print_debug("\r\n");
426 print_debug("Clearing initial memory region: ");
428 print_debug("No cache as ram now - ");
430 /* store cpu_reset to ebx */
437 #define CLEAR_FIRST_1M_RAM 1
438 #include "cpu/amd/car/cache_as_ram_post.c"
441 #undef CLEAR_FIRST_1M_RAM
442 #include "cpu/amd/car/cache_as_ram_post.c"
446 /* set new esp */ /* before _RAMBASE */
449 ::"a"( (DCACHE_RAM_BASE + DCACHE_RAM_SIZE)- _RAMBASE )
453 unsigned new_cpu_reset;
455 /* get back cpu_reset from ebx */
458 :"=a" (new_cpu_reset)
461 /* We can not go back any more, we lost old stack data in cache as ram*/
462 if(new_cpu_reset==0) {
463 print_debug("Use Ram as Stack now - done\r\n");
466 print_debug("Use Ram as Stack now - \r\n");
469 printk_debug("new_cpu_reset = %08x\r\n", new_cpu_reset);
471 print_debug("new_cpu_reset = "); print_debug_hex32(new_cpu_reset); print_debug("\r\n");
474 /*copy and execute linuxbios_ram */
475 copy_and_run(new_cpu_reset);
476 /* We will not return */
481 print_err("should not be here -\r\n");