Add support for the MSI K9ND Master Series (ms9282) board.
[coreboot.git] / src / mainboard / msi / ms9282 / failover.c
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2006 AMD
5  * Written by Yinghai Lu <yinghailu@amd.com> for AMD.
6  *
7  * Copyright (C) 2006 MSI
8  * Written by Bingxun Shi <bingxunshi@gmail.com> for MSI.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23  */
24
25 #define ASSEMBLY 1
26 #include <stdint.h>
27 #include <device/pci_def.h>
28 #include <device/pci_ids.h>
29 #include <arch/io.h>
30 #include <arch/romcc_io.h>
31 #include <cpu/x86/lapic.h>
32 #include "pc80/mc146818rtc_early.c"
33
34 #include "southbridge/nvidia/mcp55/mcp55_enable_rom.c"
35 #include "northbridge/amd/amdk8/early_ht.c"
36 #include "cpu/x86/lapic/boot_cpu.c"
37 #include "cpu/x86/mtrr/earlymtrr.c"
38 #include "northbridge/amd/amdk8/reset_test.c"
39
40 static void sio_setup(void)
41 {
42
43         unsigned value;
44        uint32_t dword;
45        uint8_t byte;
46
47         byte = pci_read_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0x7b);
48         byte |= 0x20;
49         pci_write_config8(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0x7b, byte);
50
51        dword = pci_read_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0xa0);
52        dword |= (1<<0);
53        pci_write_config32(PCI_DEV(0, MCP55_DEVN_BASE+1 , 0), 0xa0, dword);
54
55
56 }
57
58 #if CONFIG_LOGICAL_CPUS==1
59 #include "cpu/amd/dualcore/dualcore_id.c"
60 #endif
61
62 static unsigned long main(unsigned long bist)
63 {
64         /* Make cerain my local apic is useable */
65         enable_lapic();
66
67         /* Is this a cpu only reset? */
68         if (early_mtrr_init_detected()) {
69                if (last_boot_normal()) {
70                        goto normal_image;
71                } else {
72                        goto fallback_image;
73                }
74        }
75
76        /* Is this a secondary cpu? */
77        if (!boot_cpu()) {
78                if (last_boot_normal()) {
79                        goto normal_image;
80                } else {
81                        goto fallback_image;
82                }
83        }
84
85        /* Nothing special needs to be done to find bus 0 */
86        /* Allow the HT devices to be found */
87
88        enumerate_ht_chain();
89
90        sio_setup();
91
92        /* Setup the mcp55 */
93        mcp55_enable_rom();
94
95        /* Is this a deliberate reset by the bios */
96        if (bios_reset_detected() && last_boot_normal()) {
97                goto normal_image;
98        }
99        /* This is the primary cpu how should I boot? */
100        else if (do_normal_boot()) {
101                goto normal_image;
102        }
103        else {
104                goto fallback_image;
105        }
106  normal_image:
107        asm volatile ("jmp __normal_image"
108                : /* outputs */
109                : "a" (bist) /* inputs */
110                : /* clobbers */
111                );
112  fallback_image:
113        return bist;
114 }