This patch drops arch/i386/lib/console.c and arch/i386/lib/console_print.c and
[coreboot.git] / src / mainboard / dell / s1850 / romstage.c
1 #include <stdint.h>
2 #include <device/pci_def.h>
3 #include <arch/io.h>
4 #include <device/pnp_def.h>
5 #include <arch/romcc_io.h>
6 #include <cpu/x86/lapic.h>
7 #include <stdlib.h>
8 #include "option_table.h"
9 #include "pc80/mc146818rtc_early.c"
10 #include "pc80/serial.c"
11 #include "console/console.c"
12 #include "lib/ramtest.c"
13 #include "southbridge/intel/i82801ex/i82801ex_early_smbus.c"
14 #include "northbridge/intel/e7520/raminit.h"
15 #include "superio/nsc/pc8374/pc8374_early_init.c"
16 #include "cpu/x86/lapic/boot_cpu.c"
17 #include "cpu/x86/mtrr/earlymtrr.c"
18 #include "debug.c"
19 #include "watchdog.c"
20 // Remove comment if resets in this file are actually used.
21 // #include "reset.c"
22 #include "s1850_fixups.c"
23 #include "northbridge/intel/e7520/memory_initialized.c"
24 #include "cpu/x86/bist.h"
25
26 #define SIO_GPIO_BASE 0x680
27 #define SIO_XBUS_BASE 0x4880
28
29 #define CONSOLE_SERIAL_DEV PNP_DEV(0x2e, PC8374_SP1)
30
31 #define DEVPRES_CONFIG  ( \
32         DEVPRES_D0F0 | \
33         DEVPRES_D1F0 | \
34         DEVPRES_D2F0 | \
35         DEVPRES_D3F0 | \
36         DEVPRES_D4F0 | \
37         DEVPRES_D6F0 | \
38         0 )
39 #define DEVPRES1_CONFIG (DEVPRES1_D0F1 | DEVPRES1_D8F0)
40
41 #define RECVENA_CONFIG  0x0808090a
42 #define RECVENB_CONFIG  0x0808090a
43
44 static inline void activate_spd_rom(const struct mem_controller *ctrl)
45 {
46         /* nothing to do */
47 }
48 static inline int spd_read_byte(unsigned device, unsigned address)
49 {
50         return smbus_read_byte(device, address);
51 }
52
53 /* this is very highly mainboard dependent, related to wiring */
54 /* from factory BIOS via lspci */
55 #define DIMM_MAP_LOGICAL 0x2841
56 #include "northbridge/intel/e7520/raminit.c"
57 #include "lib/generic_sdram.c"
58
59 /* IPMI garbage. This is all test stuff, if it really works we'll move it somewhere
60  */
61
62 #define nftransport  0xc
63
64 #define OBF  0
65 #define IBF 1
66
67 #define ipmidata  0xca0
68 #define ipmicsr  0xca4
69
70 static inline void  ibfzero(void)
71 {
72         while(inb(ipmicsr) &  (1<<IBF)) 
73                 ;
74 }
75 static inline void  clearobf(void)
76 {
77         (void) inb(ipmidata);
78 }
79
80 static inline void  waitobf(void)
81 {
82         while((inb(ipmicsr) &  (1<<OBF)) == 0) 
83                 ;
84 }
85 /* quite possibly the stupidest interface ever designed. */
86 static inline void  first_cmd_byte(unsigned char byte)
87 {
88         ibfzero();
89         clearobf();
90         outb(0x61, ipmicsr);
91         ibfzero();
92         clearobf();
93         outb(byte, ipmidata);
94 }
95
96 static inline void  next_cmd_byte(unsigned char byte)
97 {
98
99         ibfzero();
100         clearobf();
101         outb(byte, ipmidata);
102 }
103
104 static inline void  last_cmd_byte(unsigned char byte)
105 {
106         outb(0x62, ipmicsr);
107
108         ibfzero();
109         clearobf();
110         outb(byte,  ipmidata);
111 }
112
113 static inline void read_response_byte(void)
114 {
115         int val = -1;
116         if ((inb(ipmicsr)>>6) != 1)
117                 return;
118
119         ibfzero();
120         waitobf();
121         val = inb(ipmidata);
122         outb(0x68, ipmidata);
123
124         /* see if it is done */
125         if ((inb(ipmicsr)>>6) != 1){
126                 /* wait for the dummy read. Which describes this protocol */
127                 waitobf();
128                 (void)inb(ipmidata);
129         }
130 }
131
132 static inline void ipmidelay(void)
133 {
134         int i;
135         for(i = 0; i < 1000; i++) {
136                 inb(0x80);
137         }
138 }
139
140 static inline void bmc_foad(void)
141 {
142         unsigned char c;
143         /* be safe; make sure it is really ready */
144         while ((inb(ipmicsr)>>6)) {
145                 outb(0x60, ipmicsr);
146                 inb(ipmidata);
147         }
148         first_cmd_byte(nftransport << 2);
149         ipmidelay();
150         next_cmd_byte(0x12);
151         ipmidelay();
152         next_cmd_byte(2);
153         ipmidelay();
154         last_cmd_byte(3);
155         ipmidelay();
156 }
157
158 /* end IPMI garbage */
159
160 static void main(unsigned long bist)
161 {
162         u8 b;
163         u16 w;
164         u32 l;
165         int do_reset;
166         /*
167          * 
168          * 
169          */
170         static const struct mem_controller mch[] = {
171                 {
172                         .node_id = 0,
173                         /*
174                         .f0 = PCI_DEV(0, 0x00, 0),
175                         .f1 = PCI_DEV(0, 0x00, 1),
176                         .f2 = PCI_DEV(0, 0x00, 2),
177                         .f3 = PCI_DEV(0, 0x00, 3),
178                         */
179                         /* the wiring on this part is really messed up */
180                         /* this is my best guess so far */
181                         .channel0 = {(0xa<<3)|0, (0xa<<3)|1, (0xa<<3)|2, (0xa<<3)|3, },
182                         .channel1 = {(0xa<<3)|4, (0xa<<3)|5, (0xa<<3)|6, (0xa<<3)|7, },
183                 }
184         };
185
186         /* superio setup */
187         /* observed from serialice */
188         static const u8 earlyinit[] = {
189                 0x21, 0x11, 0x11,
190                 0x22, 1, 1,
191                 0x23, 05, 05,
192                 0x24, 0x81, 0x81,
193                 0x26, 0, 0,
194                 0,
195         };
196
197         /* using SerialICE, we've seen this basic reset sequence on the dell. 
198          * we don't understand it as it uses undocumented registers, but
199          * we're going to clone it. 
200          */
201         /* enable a hidden device. */
202         b = pci_read_config8(PCI_DEV(0, 0, 0), 0xf4);
203         b |= 0x8;
204         pci_write_config8(PCI_DEV(0, 0, 0), 0xf4, b);
205
206         /* read-write lock in CMOS on LPC bridge on ICH5 */
207         pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xd8, 4);
208
209         /* operate on undocumented device */
210         l = pci_read_config32(PCI_DEV(0, 0, 2), 0xa4);
211         l |= 0x1000;
212         pci_write_config32(PCI_DEV(0, 0, 2), 0xa4, l);
213
214         l = pci_read_config32(PCI_DEV(0, 0, 2), 0x9c);
215         l |= 0x8000;
216         pci_write_config32(PCI_DEV(0, 0, 2), 0x9c, l);
217
218         /* disable undocumented device */
219         b = pci_read_config8(PCI_DEV(0, 0, 0), 0xf4);
220         b &= ~0x8;
221         pci_write_config8(PCI_DEV(0, 0, 0), 0xf4, b);
222         
223         /* set up LPC bridge bits, some of which reply on undocumented
224          * registers
225          */
226         
227         b= pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xd8);
228         b |= 4;
229         pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xd8, b);
230
231         b= pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xd4);
232         b |= 2;
233         pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xd4, b);
234
235         /* ACPI base address */
236         pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x40, 0x800);
237
238         /* Enable specific ACPI features */
239         b= pci_read_config8(PCI_DEV(0, 0x1f, 0), 0x44);
240         b |= 0x10;
241         pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44, b);
242
243         /* ACPI control */
244         w = inw(0x868);
245         outw(w|0x800, 0x868);
246         w = inw(0x866);
247         outw(w|2, 0x866);
248
249 #if 0 
250         /*seriaice shows
251         dell does this so leave it here so I don't forget 
252          */
253         /* SMBUS */
254         pci_write_config16(PCI_DEV(0, 0x1f, 3), 0x20, 0x08c0);
255
256         /* unknown */
257         b = inb(0x8c2);
258         outb(0xdf, 0x8c2);
259 #endif
260
261         /* another device enable? */
262         b = pci_read_config8(PCI_DEV(0, 0, 0), 0xf4);
263         b |= 2;
264         pci_write_config8(PCI_DEV(0, 0, 0), 0xf4, b);
265         
266         /* ?? */
267         l = pci_read_config32(PCI_DEV(0, 8, 0), 0xc0);
268         do_reset = l & 0x8000000;
269         l |= 0x8000000;
270         pci_write_config32(PCI_DEV(0, 8, 0), 0xc0, l);
271
272         if (! do_reset) {
273                 outb(2, 0xcf9);
274                 outb(6, 0xcf9);
275         }
276         if (bist == 0) {
277                 /* Skip this if there was a built in self test failure */
278                 early_mtrr_init();
279                 if (memory_initialized()) {
280                         asm volatile ("jmp __cpu_reset");
281                 }
282         }
283         /* Setup the console */
284         mainboard_set_ich5();
285         //bmc_foad();
286         pc8374_enable_dev(CONSOLE_SERIAL_DEV, CONFIG_TTYS0_BASE);
287         uart_init();
288         console_init();
289
290         /* stuff we seem to need */
291         pc8374_enable_dev(PNP_DEV(0x2e, PC8374_KBCK), 0);
292
293         /* GPIOs */
294         pc8374_enable_dev(PNP_DEV(0x2e, PC8374_GPIO), 0xc20);
295
296         /* keep this in mind.
297         SerialICE-hlp: outb 002e <= 23
298         SerialICE-hlp:  inb 002f => 05
299         SerialICE-hlp: outb 002f <= 05
300         SerialICE-hlp: outb 002e <= 24
301         SerialICE-hlp:  inb 002f => c1
302         SerialICE-hlp: outb 002f <= c1
303          */
304
305         /* Halt if there was a built in self test failure */
306 //      report_bist_failure(bist);
307
308         /* MOVE ME TO A BETTER LOCATION !!! */
309         /* config LPC decode for flash memory access */
310         device_t dev;
311         dev = pci_locate_device(PCI_ID(0x8086, 0x24d0), 0);
312         if (dev == PCI_DEV_INVALID) {
313                 die("Missing ich5?");
314         }
315         pci_write_config32(dev, 0xe8, 0x00000000);
316         pci_write_config8(dev, 0xf0, 0x00);
317
318 #if 0
319         display_cpuid_update_microcode();
320 #endif
321 #if 1
322         print_pci_devices();
323 #endif
324 #if 1
325         enable_smbus();
326 #endif
327 #if 0
328 //      dump_spd_registers(&cpu[0]);
329         int i;
330         for(i = 0; i < 1; i++) {
331                 dump_spd_registers();
332         }
333 #endif
334 #if 1
335         show_dram_slots();
336 #endif
337         disable_watchdogs();
338 //      dump_ipmi_registers();
339         mainboard_set_e7520_leds();     
340 //      memreset_setup();
341
342         sdram_initialize(ARRAY_SIZE(mch), mch);
343 #if 0
344         dump_pci_devices();
345 #endif
346 #if 1
347         dump_pci_device(PCI_DEV(0, 0x00, 0));
348 //      dump_bar14(PCI_DEV(0, 0x00, 0));
349 #endif
350
351 #if 1 // temporarily disabled 
352         /* Check the first 1M */
353 //      ram_check(0x00000000, 0x000100000);
354 //      ram_check(0x00000000, 0x000a0000);
355 //      ram_check(0x00100000, 0x01000000);
356         ram_check(0x00100000, 0x00100100);
357         /* check the first 1M in the 3rd Gig */
358 //      ram_check(0x30100000, 0x31000000);
359 #endif
360 #if 0
361         ram_check(0x00000000, 0x02000000);
362 #endif
363         
364 #if 0   
365         while(1) {
366                 hlt();
367         }
368 #endif
369 }
370