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