fb092e72037b067f4964b0fd4d82c72ca63b01f6
[coreboot.git] / src / mainboard / tyan / s2891 / failover.c
1 #define ASSEMBLY 1
2 #include <stdint.h>
3 #include <device/pci_def.h>
4 #include <device/pci_ids.h>
5 #include <arch/io.h>
6 #include <arch/romcc_io.h>
7 #include <cpu/x86/lapic.h>
8 #include "pc80/mc146818rtc_early.c"
9
10 #include "southbridge/nvidia/ck804/ck804_enable_rom.c"
11 #include "northbridge/amd/amdk8/early_ht.c"
12 #include "cpu/x86/lapic/boot_cpu.c"
13 #include "northbridge/amd/amdk8/reset_test.c"
14
15 static void sio_setup(void)
16 {
17         
18         unsigned value;
19         uint32_t dword;
20         uint8_t byte;
21
22         byte = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b);
23         byte |= 0x20; 
24         pci_write_config8(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b, byte);
25         
26         dword = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0);
27         dword |= (1<<0) | (1<<1);  
28         pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0, dword);
29
30 #if 1
31         dword = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa4);
32         dword |= (1<<16);  
33         pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa4, dword);
34
35 #endif
36
37 }
38
39
40 static unsigned long main(unsigned long bist)
41 {
42         unsigned nodeid;
43         /* Make cerain my local apic is useable */
44         enable_lapic();
45
46         nodeid = lapicid();
47         /* Is this a cpu only reset? */
48         if (cpu_init_detected(nodeid)) {
49                 if (last_boot_normal()) {
50                         goto normal_image;
51                 } else {
52                         goto cpu_reset;
53                 }
54         }
55         
56         /* Is this a secondary cpu? */
57         if (!boot_cpu()) {
58                 if (last_boot_normal()) {
59                         goto normal_image;
60                 } else {
61                         goto fallback_image;
62                 }
63         }
64
65         /* Nothing special needs to be done to find bus 0 */
66         /* Allow the HT devices to be found */
67         
68         enumerate_ht_chain();
69
70         sio_setup();
71
72         /* Setup the ck804 */
73         ck804_enable_rom();
74
75         /* Is this a deliberate reset by the bios */
76         if (bios_reset_detected() && last_boot_normal()) {
77                 goto normal_image;
78         }
79         /* This is the primary cpu how should I boot? */
80         else if (do_normal_boot()) {
81                 goto normal_image;
82         }
83         else {
84                 goto fallback_image;
85         }
86  normal_image:
87         asm volatile ("jmp __normal_image" 
88                 : /* outputs */ 
89                 : "a" (bist) /* inputs */
90                 : /* clobbers */
91                 );
92  cpu_reset:
93 #if 0
94         //CPU reset will reset memtroller ???
95         asm volatile ("jmp __cpu_reset" 
96                 : /* outputs */ 
97                 : "a"(bist) /* inputs */
98                 : /* clobbers */
99                 );
100 #endif
101
102  fallback_image:
103         return bist;
104 }