Revision: linuxbios@linuxbios.org--devel/freebios--devel--2.0--patch-34
[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 #if CONFIG_LOGICAL_CPUS==1
54 #include "cpu/amd/dualcore/dualcore_id.c"
55 #else
56 #include "cpu/amd/model_fxx/node_id.c"
57 #endif
58
59
60 static unsigned long main(unsigned long bist)
61 {
62 #if CONFIG_LOGICAL_CPUS==1
63         struct node_core_id id;
64 #else
65         unsigned nodeid;
66 #endif
67         /* Make cerain my local apic is useable */
68 //        enable_lapic();
69
70 #if CONFIG_LOGICAL_CPUS==1
71         id = get_node_core_id_x();
72         /* Is this a cpu only reset? */
73         if (cpu_init_detected(id.nodeid)) {
74 #else
75         nodeid = get_node_id();
76         /* Is this a cpu only reset? */
77         if (cpu_init_detected(nodeid)) {
78 #endif
79                 if (last_boot_normal()) {
80                         goto normal_image;
81                 } else {
82                         goto cpu_reset;
83                 }
84         }
85         
86         /* Is this a secondary cpu? */
87         if (!boot_cpu()) {
88                 if (last_boot_normal()) {
89                         goto normal_image;
90                 } else {
91                         goto fallback_image;
92                 }
93         }
94
95         /* Nothing special needs to be done to find bus 0 */
96         /* Allow the HT devices to be found */
97         
98         enumerate_ht_chain();
99
100         sio_setup();
101
102         /* Setup the ck804 */
103         ck804_enable_rom();
104
105         /* Is this a deliberate reset by the bios */
106         if (bios_reset_detected() && last_boot_normal()) {
107                 goto normal_image;
108         }
109         /* This is the primary cpu how should I boot? */
110         else if (do_normal_boot()) {
111                 goto normal_image;
112         }
113         else {
114                 goto fallback_image;
115         }
116  normal_image:
117         asm volatile ("jmp __normal_image" 
118                 : /* outputs */ 
119                 : "a" (bist) /* inputs */
120                 : /* clobbers */
121                 );
122  cpu_reset:
123 #if 0
124         //CPU reset will reset memtroller ???
125         asm volatile ("jmp __cpu_reset" 
126                 : /* outputs */ 
127                 : "a"(bist) /* inputs */
128                 : /* clobbers */
129                 );
130 #endif
131
132  fallback_image:
133         return bist;
134 }