Revision: linuxbios@linuxbios.org--devel/freebios--devel--2.0--patch-38
[coreboot.git] / src / mainboard / via / epia / auto.c
1 #define ASSEMBLY 1
2
3 #include <stdint.h>
4 #include <device/pci_def.h>
5 #if 0
6 #include <cpu/x86/lapic.h>
7 #endif
8 #include <arch/io.h>
9 #include <device/pnp_def.h>
10 #include <arch/romcc_io.h>
11 #include <arch/hlt.h>
12 #include "pc80/serial.c"
13 #include "arch/i386/lib/console.c"
14 #include "ram/ramtest.c"
15 #include "northbridge/via/vt8601/raminit.h"
16 #include "cpu/x86/mtrr/earlymtrr.c"
17 #include "cpu/x86/bist.h"
18
19 /*
20  */
21 void udelay(int usecs) 
22 {
23         int i;
24         for(i = 0; i < usecs; i++)
25                 outb(i&0xff, 0x80);
26 }
27
28 #include "lib/delay.c"
29 #include "cpu/x86/lapic/boot_cpu.c"
30 #include "debug.c"
31
32 #include "southbridge/via/vt8231/vt8231_early_smbus.c"
33
34
35 #include "southbridge/via/vt8231/vt8231_early_serial.c"
36 static void memreset_setup(void)
37 {
38 }
39
40 /*
41   static void memreset(int controllers, const struct mem_controller *ctrl)
42   {
43   }
44 */
45 static inline int spd_read_byte(unsigned device, unsigned address)
46 {
47         unsigned char c;
48         c = smbus_read_byte(device, address);
49         return c;
50 }
51
52
53
54 #include "northbridge/via/vt8601/raminit.c"
55 /*
56   #include "sdram/generic_sdram.c"
57 */
58
59 static void enable_mainboard_devices(void) 
60 {
61         device_t dev;
62         /* dev 0 for southbridge */
63   
64         dev = pci_locate_device(PCI_ID(0x1106,0x8231), 0);
65   
66         if (dev == PCI_DEV_INVALID) {
67                 die("Southbridge not found!!!\n");
68         }
69         pci_write_config8(dev, 0x50, 7);
70         pci_write_config8(dev, 0x51, 0xff);
71 #if 0
72         // This early setup switches IDE into compatibility mode before PCI gets 
73         // // a chance to assign I/Os
74         //         movl    $CONFIG_ADDR(0, 0x89, 0x42), %eax
75         //         //      movb    $0x09, %dl
76         //                 movb    $0x00, %dl
77         //                         PCI_WRITE_CONFIG_BYTE
78         //
79 #endif
80         /* we do this here as in V2, we can not yet do raw operations 
81          * to pci!
82          */
83         dev += 0x100; /* ICKY */
84
85         pci_write_config8(dev, 0x42, 0);
86 }
87
88 static void enable_shadow_ram(void) 
89 {
90         device_t dev = 0; /* no need to look up 0:0.0 */
91         unsigned char shadowreg;
92         /* dev 0 for southbridge */
93         shadowreg = pci_read_config8(dev, 0x63);
94         /* 0xf0000-0xfffff */
95         shadowreg |= 0x30;
96         pci_write_config8(dev, 0x63, shadowreg);
97 }
98
99 static void main(unsigned long bist)
100 {
101         unsigned long x;
102         
103         if (bist == 0) {
104                 early_mtrr_init();
105         }
106         enable_vt8231_serial();
107         uart_init();
108         console_init();
109
110         /* Halt if there was a built in self test failure */
111         report_bist_failure(bist);
112         
113         enable_mainboard_devices();
114         enable_smbus();
115         enable_shadow_ram();
116         /*
117           memreset_setup();
118           this is way more generic than we need.
119           sdram_initialize(sizeof(cpu)/sizeof(cpu[0]), cpu);
120         */
121         sdram_set_registers((const struct mem_controller *) 0);
122         sdram_set_spd_registers((const struct mem_controller *) 0);
123         sdram_enable(0, (const struct mem_controller *) 0);
124         
125         /* Check all of memory */
126 #if 0
127         ram_check(0x00000000, msr.lo);
128 #endif
129 #if 0
130         static const struct {
131                 unsigned long lo, hi;
132         } check_addrs[] = {
133                 /* Check 16MB of memory @ 0*/
134                 { 0x00000000, 0x01000000 },
135 #if TOTAL_CPUS > 1
136                 /* Check 16MB of memory @ 2GB */
137                 { 0x80000000, 0x81000000 },
138 #endif
139         };
140         int i;
141         for(i = 0; i < sizeof(check_addrs)/sizeof(check_addrs[0]); i++) {
142                 ram_check(check_addrs[i].lo, check_addrs[i].hi);
143         }
144 #endif
145 }