4 #define RAMINIT_SYSINFO 0
6 #if CONFIG_LOGICAL_CPUS==1
7 #define SET_NB_CFG_54 1
11 #define K8_4RANK_DIMM_SUPPORT 1
15 #define ENABLE_APIC_EXT_ID 1
16 #define APIC_ID_OFFSET 0x10
17 #define LIFT_BSP_APIC_ID 0
19 #define ENABLE_APIC_EXT_ID 0
22 //used by incoherent_ht
23 //#define K8_SCAN_PCI_BUS 1
24 //#define K8_ALLOCATE_IO_RANGE 1
27 #include <device/pci_def.h>
29 #include <device/pnp_def.h>
30 #include <arch/romcc_io.h>
31 #include <cpu/x86/lapic.h>
32 #include "option_table.h"
33 #include "pc80/mc146818rtc_early.c"
34 #include "pc80/serial.c"
35 #include "arch/i386/lib/console.c"
36 #include "ram/ramtest.c"
39 static void post_code(uint8_t value) {
42 for(i=0;i<0x80000;i++) {
49 #include <cpu/amd/model_fxx_rev.h>
50 #include "northbridge/amd/amdk8/incoherent_ht.c"
51 #include "southbridge/amd/amd8111/amd8111_early_smbus.c"
52 #include "northbridge/amd/amdk8/raminit.h"
53 #include "cpu/amd/model_fxx/apic_timer.c"
54 #include "lib/delay.c"
56 #if CONFIG_USE_INIT == 0
57 #include "lib/memcpy.c"
60 #include "cpu/x86/lapic/boot_cpu.c"
61 #include "northbridge/amd/amdk8/reset_test.c"
62 #include "northbridge/amd/amdk8/debug.c"
63 #include "superio/winbond/w83627hf/w83627hf_early_serial.c"
65 #include "cpu/amd/mtrr/amd_earlymtrr.c"
66 #include "cpu/x86/bist.h"
68 #include "northbridge/amd/amdk8/setup_resource_map.c"
70 #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
72 static void hard_reset(void)
75 unsigned sblnk = get_sblnk();
78 #if HT_CHAIN_END_UNITID_BASE < HT_CHAIN_UNITID_BASE
79 dev = PCI_DEV(node_link_to_bus(0, sblnk), 2 + HT_CHAIN_END_UNITID_BASE - 1, 3);
81 dev = PCI_DEV(node_link_to_bus(0, sblnk), 4 + HT_CHAIN_UNITID_BASE - 1, 3);
87 pci_write_config8(dev, 0x41, 0xf1);
91 static void soft_reset(void)
94 unsigned sblnk = get_sblnk();
97 #if HT_CHAIN_END_UNITID_BASE < HT_CHAIN_UNITID_BASE
98 dev = PCI_DEV(node_link_to_bus(0, sblnk), 2 + HT_CHAIN_END_UNITID_BASE - 1, 0);
100 dev = PCI_DEV(node_link_to_bus(0, sblnk), 4 + HT_CHAIN_UNITID_BASE - 1, 0);
104 pci_write_config8(dev, 0x47, 1);
107 static void memreset_setup(void)
109 if (is_cpu_pre_c0()) {
110 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=0
113 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=1
115 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 17);
118 static void memreset(int controllers, const struct mem_controller *ctrl)
120 if (is_cpu_pre_c0()) {
122 outb((0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 17); //REVB_MEMRST_L=1
127 static inline void activate_spd_rom(const struct mem_controller *ctrl)
129 #define SMBUS_HUB 0x18
131 unsigned device=(ctrl->channel0[0])>>8;
132 /* the very first write always get COL_STS=1 and ABRT_STS=1, so try another time*/
135 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
136 } while ((ret!=0) && (i-->0));
138 smbus_write_byte(SMBUS_HUB, 0x03, 0);
141 static inline void change_i2c_mux(unsigned device)
143 #define SMBUS_HUB 0x18
145 print_debug("change_i2c_mux i="); print_debug_hex8(device); print_debug("\r\n");
148 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
149 print_debug("change_i2c_mux 1 ret="); print_debug_hex32(ret); print_debug("\r\n");
150 } while ((ret!=0) && (i-->0));
151 ret = smbus_write_byte(SMBUS_HUB, 0x03, 0);
152 print_debug("change_i2c_mux 2 ret="); print_debug_hex32(ret); print_debug("\r\n");
156 static inline int spd_read_byte(unsigned device, unsigned address)
158 return smbus_read_byte(device, address);
162 #include "northbridge/amd/amdk8/raminit.c"
163 #include "northbridge/amd/amdk8/coherent_ht.c"
164 #include "sdram/generic_sdram.c"
166 /* tyan does not want the default */
167 #include "resourcemap.c"
169 #include "cpu/amd/dualcore/dualcore.c"
171 #define RC0 ((1<<0)<<8)
172 #define RC1 ((1<<1)<<8)
177 #include "cpu/amd/car/copy_and_run.c"
178 #include "cpu/amd/car/post_cache_as_ram.c"
180 #include "cpu/amd/model_fxx/init_cpus.c"
182 #if USE_FALLBACK_IMAGE == 1
184 #include "southbridge/amd/amd8111/amd8111_enable_rom.c"
185 #include "northbridge/amd/amdk8/early_ht.c"
187 void failover_process(unsigned long bist, unsigned long cpu_init_detectedx)
189 unsigned last_boot_normal_x = last_boot_normal();
191 /* Is this a cpu only reset? or Is this a secondary cpu? */
192 if ((cpu_init_detectedx) || (!boot_cpu())) {
193 if (last_boot_normal_x) {
200 /* Nothing special needs to be done to find bus 0 */
201 /* Allow the HT devices to be found */
203 enumerate_ht_chain();
205 /* Setup the flash access */
206 amd8111_enable_rom();
208 /* Is this a deliberate reset by the bios */
210 if (bios_reset_detected() && last_boot_normal_x) {
213 /* This is the primary cpu how should I boot? */
214 else if (do_normal_boot()) {
222 __asm__ volatile ("jmp __normal_image"
224 : "a" (bist), "b" (cpu_init_detectedx) /* inputs */
233 void real_main(unsigned long bist, unsigned long cpu_init_detectedx);
235 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
238 #if USE_FALLBACK_IMAGE == 1
239 failover_process(bist, cpu_init_detectedx);
241 real_main(bist, cpu_init_detectedx);
245 void real_main(unsigned long bist, unsigned long cpu_init_detectedx)
247 static const uint16_t spd_addr [] = {
250 #if CONFIG_MAX_PHYSICAL_CPUS > 1
257 unsigned cpu_reset = 0;
258 unsigned bsp_apicid = 0;
260 struct mem_controller ctrl[8];
264 bsp_apicid = init_cpus(cpu_init_detectedx);
269 w83627hf_enable_serial(SERIAL_DEV, TTYS0_BASE);
273 // dump_mem(DCACHE_RAM_BASE+DCACHE_RAM_SIZE-0x200, DCACHE_RAM_BASE+DCACHE_RAM_SIZE);
275 /* Halt if there was a built in self test failure */
276 report_bist_failure(bist);
278 print_debug("bsp_apicid="); print_debug_hex8(bsp_apicid); print_debug("\r\n");
280 setup_serengeti_leopard_resource_map();
282 dump_pci_device(PCI_DEV(0, 0x18, 0));
283 dump_pci_device(PCI_DEV(0, 0x19, 0));
286 needs_reset = setup_coherent_ht_domain();
288 #if CONFIG_LOGICAL_CPUS==1
289 // It is said that we should start core1 after all core0 launched
290 wait_all_core0_started();
293 wait_all_aps_started(bsp_apicid);
295 needs_reset |= ht_setup_chains_x();
298 print_info("ht reset -\r\n");
302 allow_all_aps_stop(bsp_apicid);
305 //It's the time to set ctrl now;
306 fill_mem_ctrl(nodes, ctrl, spd_addr);
310 dump_spd_registers(&cpu[0]);
313 dump_smbus_registers();
318 // init_timer(); // Need to use TMICT to synconize FID/VID
320 sdram_initialize(nodes, ctrl);
330 post_cache_as_ram(cpu_reset);