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