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)
39 /* Look up a which bus a given node/link combination is on.
40 * return 0 when we can't find the answer.
42 static unsigned node_link_to_bus(unsigned node, unsigned link)
46 for(reg = 0xE0; reg < 0xF0; reg += 0x04) {
48 config_map = pci_read_config32(PCI_DEV(0, 0x18, 1), reg);
49 if ((config_map & 3) != 3) {
52 if ((((config_map >> 4) & 7) == node) &&
53 (((config_map >> 8) & 3) == link))
55 return (config_map >> 16) & 0xff;
61 static void hard_reset(void)
66 dev = PCI_DEV(node_link_to_bus(0, 0), 0x04, 3);
71 pci_write_config8(dev, 0x41, 0xf1);
76 static void soft_reset(void)
81 dev = PCI_DEV(node_link_to_bus(0, 0), 0x04, 0);
84 pci_write_config8(dev, 0x47, 1);
87 static void memreset_setup(void)
89 if (is_cpu_pre_c0()) {
90 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=0
93 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=1
95 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 17);
98 static void memreset(int controllers, const struct mem_controller *ctrl)
100 if (is_cpu_pre_c0()) {
102 outb((0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 17); //REVB_MEMRST_L=1
107 static inline void activate_spd_rom(const struct mem_controller *ctrl)
112 static inline int spd_read_byte(unsigned device, unsigned address)
114 return smbus_read_byte(device, address);
117 #define K8_4RANK_DIMM_SUPPORT 1
119 #include "northbridge/amd/amdk8/raminit.c"
120 #include "northbridge/amd/amdk8/resourcemap.c"
121 #include "northbridge/amd/amdk8/coherent_ht.c"
122 #include "sdram/generic_sdram.c"
124 #if CONFIG_LOGICAL_CPUS==1
125 #define SET_NB_CFG_54 1
126 #include "cpu/amd/dualcore/dualcore.c"
128 #include "cpu/amd/model_fxx/node_id.c"
133 #define TOTAL_CPUS (FIRST_CPU + SECOND_CPU)
135 #include "cpu/amd/car/copy_and_run.c"
137 #if USE_FALLBACK_IMAGE == 1
139 #include "southbridge/amd/amd8111/amd8111_enable_rom.c"
140 #include "northbridge/amd/amdk8/early_ht.c"
142 void real_main(unsigned long bist);
144 void amd64_main(unsigned long bist)
146 #if CONFIG_LOGICAL_CPUS==1
147 struct node_core_id id;
151 /* Make cerain my local apic is useable */
154 #if CONFIG_LOGICAL_CPUS==1
155 id = get_node_core_id_x();
156 /* Is this a cpu only reset? */
157 if (cpu_init_detected(id.nodeid)) {
159 // nodeid = lapicid();
160 nodeid = get_node_id();
161 /* Is this a cpu only reset? */
162 if (cpu_init_detected(nodeid)) {
164 if (last_boot_normal()) {
171 /* Is this a secondary cpu? */
173 if (last_boot_normal()) {
180 /* Nothing special needs to be done to find bus 0 */
181 /* Allow the HT devices to be found */
183 enumerate_ht_chain();
185 /* Setup the ck804 */
186 amd8111_enable_rom();
188 /* Is this a deliberate reset by the bios */
189 if (bios_reset_detected() && last_boot_normal()) {
192 /* This is the primary cpu how should I boot? */
193 else if (do_normal_boot()) {
200 __asm__ volatile ("jmp __normal_image"
202 : "a" (bist) /* inputs */
206 //CPU reset will reset memtroller ???
207 asm volatile ("jmp __cpu_reset"
209 : "a"(bist) /* inputs */
216 void real_main(unsigned long bist)
218 void amd64_main(unsigned long bist)
221 static const struct mem_controller cpu[] = {
225 .f0 = PCI_DEV(0, 0x18, 0),
226 .f1 = PCI_DEV(0, 0x18, 1),
227 .f2 = PCI_DEV(0, 0x18, 2),
228 .f3 = PCI_DEV(0, 0x18, 3),
229 .channel0 = { (0xa<<3)|0, (0xa<<3)|2, 0, 0 },
230 .channel1 = { (0xa<<3)|1, (0xa<<3)|3, 0, 0 },
236 .f0 = PCI_DEV(0, 0x19, 0),
237 .f1 = PCI_DEV(0, 0x19, 1),
238 .f2 = PCI_DEV(0, 0x19, 2),
239 .f3 = PCI_DEV(0, 0x19, 3),
240 .channel0 = { (0xa<<3)|4, (0xa<<3)|6, 0, 0 },
241 .channel1 = { (0xa<<3)|5, (0xa<<3)|7, 0, 0 },
247 unsigned cpu_reset = 0;
250 #if CONFIG_LOGICAL_CPUS==1
251 struct node_core_id id;
255 /* Skip this if there was a built in self test failure */
256 // amd_early_mtrr_init(); # don't need, already done in cache_as_ram
258 #if CONFIG_LOGICAL_CPUS==1
259 set_apicid_cpuid_lo();
260 id = get_node_core_id_x(); // that is initid
262 nodeid = get_node_id();
269 #if CONFIG_LOGICAL_CPUS==1
271 if (cpu_init_detected(id.nodeid)) {
275 distinguish_cpu_resets(id.nodeid);
278 if (cpu_init_detected(nodeid)) {
282 distinguish_cpu_resets(nodeid);
287 #if CONFIG_LOGICAL_CPUS==1
291 // We need stop the CACHE as RAM for this CPU too
292 #include "cpu/amd/car/cache_as_ram_post.c"
293 stop_this_cpu(); // it will stop all cores except core0 of cpu0
298 w83627hf_enable_serial(SERIAL_DEV, TTYS0_BASE);
302 /* Halt if there was a built in self test failure */
303 report_bist_failure(bist);
305 setup_default_resource_map();
307 needs_reset = setup_coherent_ht_domain();
309 #if CONFIG_LOGICAL_CPUS==1
312 needs_reset |= ht_setup_chains_x();
315 print_info("ht reset -\r\n");
322 sdram_initialize(sizeof(cpu)/sizeof(cpu[0]), cpu);
326 /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
333 printk_debug("v_esp=%08x\r\n", v_esp);
335 print_debug("v_esp="); print_debug_hex32(v_esp); print_debug("\r\n");
346 printk_debug("cpu_reset = %08x\r\n",cpu_reset);
348 print_debug("cpu_reset = "); print_debug_hex32(cpu_reset); print_debug("\r\n");
352 print_debug("Clearing initial memory region: ");
354 print_debug("No cache as ram now - ");
356 /* store cpu_reset to ebx */
363 #define CLEAR_FIRST_1M_RAM 1
364 #include "cpu/amd/car/cache_as_ram_post.c"
367 #undef CLEAR_FIRST_1M_RAM
368 #include "cpu/amd/car/cache_as_ram_post.c"
372 /* set new esp */ /* before _RAMBASE */
375 ::"a"( (DCACHE_RAM_BASE + DCACHE_RAM_SIZE)- _RAMBASE )
379 unsigned new_cpu_reset;
381 /* get back cpu_reset from ebx */
384 :"=a" (new_cpu_reset)
387 print_debug("Use Ram as Stack now - "); /* but We can not go back any more, we lost old stack data in cache as ram*/
388 if(new_cpu_reset==0) {
389 print_debug("done\r\n");
396 printk_debug("new_cpu_reset = %08x\r\n", new_cpu_reset);
398 print_debug("new_cpu_reset = "); print_debug_hex32(new_cpu_reset); print_debug("\r\n");
400 /*copy and execute linuxbios_ram */
401 copy_and_run(new_cpu_reset);
402 /* We will not return */
407 print_debug("should not be here -\r\n");