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