Revert some garbage that snuck into my trivial change, correct a spelling error.
[coreboot.git] / src / mainboard / tyan / s2895 / failover.c
1 #define ASSEMBLY 1
2 #define __ROMCC__
3
4 #include <stdint.h>
5 #include <string.h>
6 #include <device/pci_def.h>
7 #include <arch/io.h>
8 #include <device/pnp_def.h>
9 #include <arch/romcc_io.h>
10 #include <cpu/x86/lapic.h>
11 #include "option_table.h"
12 #include "pc80/mc146818rtc_early.c"
13
14 #include "cpu/x86/lapic/boot_cpu.c"
15 #include "northbridge/amd/amdk8/reset_test.c"
16
17 #include "southbridge/nvidia/ck804/ck804_enable_rom.c"
18 #include "northbridge/amd/amdk8/early_ht.c"
19
20 #define post_code(x) outb(x, 0x80)
21
22 #include "superio/smsc/lpc47b397/lpc47b397_early_serial.c"
23 #include "superio/smsc/lpc47b397/lpc47b397_early_gpio.c"
24 #define SUPERIO_GPIO_DEV PNP_DEV(0x2e, LPC47B397_RT)
25 #define SUPERIO_GPIO_IO_BASE 0x400
26
27 static void sio_setup(void)
28 {
29
30         unsigned value;
31         uint32_t dword;
32         uint8_t byte;
33
34         pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1, 0), 0xac, 0x047f0400);
35
36         byte = pci_read_config8(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b);
37         byte |= 0x20;
38         pci_write_config8(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0x7b, byte);
39
40         dword = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0);
41         dword |= (1<<29)|(1<<0);
42         pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa0, dword);
43
44         dword = pci_read_config32(PCI_DEV(0, CK804_DEVN_BASE+1, 0), 0xa4);
45         dword |= (1<<16);
46         pci_write_config32(PCI_DEV(0, CK804_DEVN_BASE+1 , 0), 0xa4, dword);
47
48         lpc47b397_enable_serial(SUPERIO_GPIO_DEV, SUPERIO_GPIO_IO_BASE);
49         value = lpc47b397_gpio_offset_in(SUPERIO_GPIO_IO_BASE, 0x77);
50         value &= 0xbf;
51         lpc47b397_gpio_offset_out(SUPERIO_GPIO_IO_BASE, 0x77, value);
52
53 }
54
55 void mainboard_bsp_init()
56 {
57         /* Nothing special needs to be done to find bus 0 */
58         /* Allow the HT devices to be found */
59
60         enumerate_ht_chain();
61
62         sio_setup();
63
64         /* Setup the ck804 */
65         ck804_enable_rom();
66 }
67
68 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
69 {
70         unsigned last_boot_normal_x = last_boot_normal();
71
72         /* Is this a cpu only reset? or Is this a secondary cpu? */
73         if ((cpu_init_detectedx) || (!boot_cpu())) {
74                 if (last_boot_normal_x) {
75                         goto normal_image;
76                 } else {
77                         goto fallback_image;
78                 }
79         }
80
81         mainboard_bsp_init();
82
83         /* Is this a deliberate reset by the bios */
84         post_code(0x22);
85         if (bios_reset_detected() && last_boot_normal_x) {
86                 goto normal_image;
87         }
88         /* This is the primary cpu how should I boot? */
89         else if (do_normal_boot()) {
90                 goto normal_image;
91         }
92         else {
93                 goto fallback_image;
94         }
95  normal_image:
96         post_code(0x23);
97         __asm__ volatile ("jmp __normal_image"
98         : /* outputs */
99         : "a" (bist), "b"(cpu_init_detectedx) /* inputs */
100         );
101
102  fallback_image:
103         post_code(0x25);
104         __asm__ volatile ("jmp __fallback_image"
105         : /* outputs */
106         : "a" (bist), "b" (cpu_init_detectedx) /* inputs */
107         );
108 }