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 /* Look up a which bus a given node/link combination is on.
41 * return 0 when we can't find the answer.
43 static unsigned node_link_to_bus(unsigned node, unsigned link)
47 for(reg = 0xE0; reg < 0xF0; reg += 0x04) {
49 config_map = pci_read_config32(PCI_DEV(0, 0x18, 1), reg);
50 if ((config_map & 3) != 3) {
53 if ((((config_map >> 4) & 7) == node) &&
54 (((config_map >> 8) & 3) == link))
56 return (config_map >> 16) & 0xff;
62 static void hard_reset(void)
67 dev = PCI_DEV(node_link_to_bus(0, 1), 0x04, 3);
72 pci_write_config8(dev, 0x41, 0xf1);
77 static void soft_reset(void)
82 dev = PCI_DEV(node_link_to_bus(0, 1), 0x04, 0);
85 pci_write_config8(dev, 0x47, 1);
88 static void memreset_setup(void)
90 if (is_cpu_pre_c0()) {
91 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=0
94 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 16); //REVC_MEMRST_EN=1
96 outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 17);
99 static void memreset(int controllers, const struct mem_controller *ctrl)
101 if (is_cpu_pre_c0()) {
103 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)
109 #define SMBUS_HUB 0x18
111 unsigned device=(ctrl->channel0[0])>>8;
112 /* the very first write always get COL_STS=1 and ABRT_STS=1, so try another time*/
115 ret = smbus_write_byte(SMBUS_HUB, 0x01, device);
116 } while ((ret!=0) && (i-->0));
118 smbus_write_byte(SMBUS_HUB, 0x03, 0);
121 static inline int spd_read_byte(unsigned device, unsigned address)
123 return smbus_read_byte(device, address);
126 #define K8_4RANK_DIMM_SUPPORT 1
128 #include "northbridge/amd/amdk8/raminit.c"
130 #define ENABLE_APIC_EXT_ID 1
131 #define APIC_ID_OFFSET 0x10
132 #define LIFT_BSP_APIC_ID 0
134 #define ENABLE_APIC_EXT_ID 0
136 #include "northbridge/amd/amdk8/coherent_ht.c"
137 #include "sdram/generic_sdram.c"
139 /* tyan does not want the default */
140 #include "resourcemap.c"
142 #if CONFIG_LOGICAL_CPUS==1
143 #define SET_NB_CFG_54 1
144 #include "cpu/amd/dualcore/dualcore.c"
146 #include "cpu/amd/model_fxx/node_id.c"
154 #define TOTAL_CPUS (FIRST_CPU + SECOND_CPU + THIRD_CPU + FOURTH_CPU)
156 #define RC0 ((1<<2)<<8)
157 #define RC1 ((1<<1)<<8)
158 #define RC2 ((1<<4)<<8)
159 #define RC3 ((1<<3)<<8)
166 #include "cpu/amd/car/copy_and_run.c"
168 #if USE_FALLBACK_IMAGE == 1
170 #include "southbridge/amd/amd8111/amd8111_enable_rom.c"
171 #include "northbridge/amd/amdk8/early_ht.c"
173 void real_main(unsigned long bist);
175 void amd64_main(unsigned long bist)
177 #if CONFIG_LOGICAL_CPUS==1
178 struct node_core_id id;
182 /* Make cerain my local apic is useable */
185 #if CONFIG_LOGICAL_CPUS==1
186 id = get_node_core_id_x();
187 /* Is this a cpu only reset? */
188 if (cpu_init_detected(id.nodeid)) {
190 // nodeid = lapicid();
191 nodeid = get_node_id();
192 /* Is this a cpu only reset? */
193 if (cpu_init_detected(nodeid)) {
195 if (last_boot_normal()) {
202 /* Is this a secondary cpu? */
204 if (last_boot_normal()) {
211 /* Nothing special needs to be done to find bus 0 */
212 /* Allow the HT devices to be found */
214 enumerate_ht_chain();
216 /* Setup the ck804 */
217 amd8111_enable_rom();
219 /* Is this a deliberate reset by the bios */
220 if (bios_reset_detected() && last_boot_normal()) {
223 /* This is the primary cpu how should I boot? */
224 else if (do_normal_boot()) {
231 __asm__ volatile ("jmp __normal_image"
233 : "a" (bist) /* inputs */
237 //CPU reset will reset memtroller ???
238 asm volatile ("jmp __cpu_reset"
240 : "a"(bist) /* inputs */
247 void real_main(unsigned long bist)
249 void amd64_main(unsigned long bist)
252 static const struct mem_controller cpu[] = {
256 .f0 = PCI_DEV(0, 0x18, 0),
257 .f1 = PCI_DEV(0, 0x18, 1),
258 .f2 = PCI_DEV(0, 0x18, 2),
259 .f3 = PCI_DEV(0, 0x18, 3),
260 .channel0 = { RC0|DIMM0, RC0|DIMM2, 0, 0 },
261 .channel1 = { RC0|DIMM1, RC0|DIMM3, 0, 0 },
267 .f0 = PCI_DEV(0, 0x19, 0),
268 .f1 = PCI_DEV(0, 0x19, 1),
269 .f2 = PCI_DEV(0, 0x19, 2),
270 .f3 = PCI_DEV(0, 0x19, 3),
271 .channel0 = { RC1|DIMM0, RC1|DIMM2 , 0, 0 },
272 .channel1 = { RC1|DIMM1, RC1|DIMM3 , 0, 0 },
280 .f0 = PCI_DEV(0, 0x1a, 0),
281 .f1 = PCI_DEV(0, 0x1a, 1),
282 .f2 = PCI_DEV(0, 0x1a, 2),
283 .f3 = PCI_DEV(0, 0x1a, 3),
284 .channel0 = { RC2|DIMM0, RC2|DIMM2, 0, 0 },
285 .channel1 = { RC2|DIMM1, RC2|DIMM3, 0, 0 },
292 .f0 = PCI_DEV(0, 0x1b, 0),
293 .f1 = PCI_DEV(0, 0x1b, 1),
294 .f2 = PCI_DEV(0, 0x1b, 2),
295 .f3 = PCI_DEV(0, 0x1b, 3),
296 .channel0 = { RC3|DIMM0, RC3|DIMM2, 0, 0 },
297 .channel1 = { RC3|DIMM1, RC3|DIMM3, 0, 0 },
304 unsigned cpu_reset = 0;
307 #if CONFIG_LOGICAL_CPUS==1
308 struct node_core_id id;
312 /* Skip this if there was a built in self test failure */
313 // amd_early_mtrr_init(); # don't need, already done in cache_as_ram
315 #if CONFIG_LOGICAL_CPUS==1
316 set_apicid_cpuid_lo();
317 id = get_node_core_id_x(); // that is initid
318 #if ENABLE_APIC_EXT_ID == 1
320 enable_apic_ext_id(id.nodeid);
324 nodeid = get_node_id();
325 #if ENABLE_APIC_EXT_ID == 1
326 enable_apic_ext_id(nodeid);
334 #if CONFIG_LOGICAL_CPUS==1
335 #if ENABLE_APIC_EXT_ID == 1
336 #if LIFT_BSP_APIC_ID == 0
337 if( id.nodeid != 0 ) //all except cores in node0
339 lapic_write(LAPIC_ID, ( lapic_read(LAPIC_ID) | (APIC_ID_OFFSET<<24) ) );
342 if (cpu_init_detected(id.nodeid)) {
346 distinguish_cpu_resets(id.nodeid);
349 #if ENABLE_APIC_EXT_ID == 1
350 #if LIFT_BSP_APIC_ID == 0
353 lapic_write(LAPIC_ID, ( lapic_read(LAPIC_ID) | (APIC_ID_OFFSET<<24) ) ); // CPU apicid is from 0x10
356 if (cpu_init_detected(nodeid)) {
360 distinguish_cpu_resets(nodeid);
364 #if CONFIG_LOGICAL_CPUS==1
368 // We need stop the CACHE as RAM for this CPU too
369 #include "cpu/amd/car/cache_as_ram_post.c"
370 stop_this_cpu(); // it will stop all cores except core0 of cpu0
374 w83627hf_enable_serial(SERIAL_DEV, TTYS0_BASE);
378 /* Halt if there was a built in self test failure */
379 report_bist_failure(bist);
381 setup_s4882_resource_map();
383 needs_reset = setup_coherent_ht_domain();
385 #if CONFIG_LOGICAL_CPUS==1
386 // It is said that we should start core1 after all core0 launched
389 needs_reset |= ht_setup_chains_x();
392 print_info("ht reset -\r\n");
399 sdram_initialize(sizeof(cpu)/sizeof(cpu[0]), cpu);
403 /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
410 printk_debug("v_esp=%08x\r\n", v_esp);
412 print_debug("v_esp="); print_debug_hex32(v_esp); print_debug("\r\n");
423 printk_debug("cpu_reset = %08x\r\n",cpu_reset);
425 print_debug("cpu_reset = "); print_debug_hex32(cpu_reset); print_debug("\r\n");
429 print_debug("Clearing initial memory region: ");
431 print_debug("No cache as ram now - ");
433 /* store cpu_reset to ebx */
440 #define CLEAR_FIRST_1M_RAM 1
441 #include "cpu/amd/car/cache_as_ram_post.c"
444 #undef CLEAR_FIRST_1M_RAM
445 #include "cpu/amd/car/cache_as_ram_post.c"
449 /* set new esp */ /* before _RAMBASE */
452 ::"a"( (DCACHE_RAM_BASE + DCACHE_RAM_SIZE)- _RAMBASE )
456 unsigned new_cpu_reset;
458 /* get back cpu_reset from ebx */
461 :"=a" (new_cpu_reset)
464 print_debug("Use Ram as Stack now - "); /* but We can not go back any more, we lost old stack data in cache as ram*/
465 if(new_cpu_reset==0) {
466 print_debug("done\r\n");
473 printk_debug("new_cpu_reset = %08x\r\n", new_cpu_reset);
475 print_debug("new_cpu_reset = "); print_debug_hex32(new_cpu_reset); print_debug("\r\n");
477 /*copy and execute linuxbios_ram */
478 copy_and_run(new_cpu_reset);
479 /* We will not return */
484 print_debug("should not be here -\r\n");