1d7c8d50281afe01282280a7024473549efc8251
[coreboot.git] / src / mainboard / intel / eagleheights / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007-2008 coresystems GmbH
5  * Copyright (C) 2009 Thomas Jourdan <thomas.jourdan@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; version 2 of
10  * the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20  * MA 02110-1301 USA
21  */
22
23 #include <delay.h>
24
25 #include <stdint.h>
26 #include <arch/io.h>
27 #include <arch/romcc_io.h>
28 #include <device/pci_def.h>
29 #include <device/pnp_def.h>
30 #include <cpu/x86/lapic.h>
31
32 #include <pc80/mc146818rtc.h>
33
34 #include <console/console.h>
35 #include <cpu/x86/bist.h>
36
37 #include "lib/ramtest.c"
38 #include "southbridge/intel/i3100/i3100_early_smbus.c"
39 #include "southbridge/intel/i3100/i3100_early_lpc.c"
40 #include "reset.c"
41 #include "superio/intel/i3100/i3100_early_serial.c"
42 #include "superio/smsc/smscsuperio/smscsuperio_early_serial.c"
43
44 /* Data */
45 #define UART_RBR 0x00
46 #define UART_TBR 0x00
47
48 /* Control */
49 #define UART_IER 0x01
50 #define UART_IIR 0x02
51 #define UART_FCR 0x02
52 #define UART_LCR 0x03
53 #define UART_MCR 0x04
54 #define UART_DLL 0x00
55 #define UART_DLM 0x01
56
57 /* Status */
58 #define UART_LSR 0x05
59 #define UART_MSR 0x06
60 #define UART_SCR 0x07
61
62 #define SIO_GPIO_BASE 0x680
63 #define SIO_XBUS_BASE 0x4880
64
65 #define DEVPRES_CONFIG  (DEVPRES_D1F0 | DEVPRES_D2F0 | DEVPRES_D3F0)
66 #define DEVPRES1_CONFIG (DEVPRES1_D0F1 | DEVPRES1_D8F0)
67
68 #define IA32_PERF_STS     0x198
69 #define IA32_PERF_CTL     0x199
70 #define MSR_THERM2_CTL    0x19D
71 #define IA32_MISC_ENABLES 0x1A0
72
73 /* SATA */
74 #define SATA_MAP 0x90
75
76 #define SATA_MODE_IDE  0x00
77 #define SATA_MODE_AHCI 0x01
78
79 /* RCBA registers */
80 #define RCBA 0xF0
81 #define DEFAULT_RCBA 0xFEA00000
82
83 #define RCBA_RPC   0x0224 /* 32 bit */
84
85 #define RCBA_TCTL  0x3000 /*  8 bit */
86
87 #define RCBA_D31IP 0x3100 /* 32 bit */
88 #define RCBA_D30IP 0x3104 /* 32 bit */
89 #define RCBA_D29IP 0x3108 /* 32 bit */
90 #define RCBA_D28IP 0x310C /* 32 bit */
91 #define RCBA_D31IR 0x3140 /* 16 bit */
92 #define RCBA_D30IR 0x3142 /* 16 bit */
93 #define RCBA_D29IR 0x3144 /* 16 bit */
94 #define RCBA_D28IR 0x3146 /* 16 bit */
95
96 #define RCBA_RTC   0x3400 /* 32 bit */
97 #define RCBA_HPTC  0x3404 /* 32 bit */
98 #define RCBA_GCS   0x3410 /* 32 bit */
99 #define RCBA_BUC   0x3414 /*  8 bit */
100 #define RCBA_FD    0x3418 /* 32 bit */
101 #define RCBA_PRC   0x341C /* 32 bit */
102
103 static inline int spd_read_byte(u16 device, u8 address)
104 {
105         return smbus_read_byte(device, address);
106 }
107
108 #include "northbridge/intel/i3100/raminit.h"
109 #include "cpu/x86/mtrr/earlymtrr.c"
110 #include "northbridge/intel/i3100/memory_initialized.c"
111 #include "northbridge/intel/i3100/raminit.c"
112 #include "lib/generic_sdram.c"
113 #include "northbridge/intel/i3100/reset_test.c"
114 #include "debug.c"
115
116 static void early_config(void)
117 {
118         u32 gcs, rpc, fd;
119
120         /* Enable RCBA */
121         pci_write_config32(PCI_DEV(0, 0x1F, 0), RCBA, DEFAULT_RCBA | 1);
122
123         /* Disable watchdog */
124         gcs = read32(DEFAULT_RCBA + RCBA_GCS);
125         gcs |= (1 << 5); /* No reset */
126         write32(DEFAULT_RCBA + RCBA_GCS, gcs);
127
128         /* Configure PCIe port B as 4x */
129         rpc = read32(DEFAULT_RCBA + RCBA_RPC);
130         rpc |= (3 << 0);
131         write32(DEFAULT_RCBA + RCBA_RPC, rpc);
132
133         /* Disable Modem, Audio, PCIe ports 2/3/4 */
134         fd = read32(DEFAULT_RCBA + RCBA_FD);
135         fd |= (1 << 19) | (1 << 18) | (1 << 17) | (1 << 6) | (1 << 5);
136         write32(DEFAULT_RCBA + RCBA_FD, fd);
137
138         /* Enable HPET */
139         write32(DEFAULT_RCBA + RCBA_HPTC, (1 << 7));
140
141         /* Improve interrupt routing
142          * D31:F2 SATA        INTB# -> PIRQD
143          * D31:F3 SMBUS       INTB# -> PIRQD
144          * D31:F4 CHAP        INTD# -> PIRQA
145          * D29:F0 USB1#1      INTA# -> PIRQH
146          * D29:F1 USB1#2      INTB# -> PIRQD
147          * D29:F7 USB2        INTA# -> PIRQH
148          * D28:F0 PCIe Port 1 INTA# -> PIRQE
149          */
150
151         write16(DEFAULT_RCBA + RCBA_D31IR, 0x0230);
152         write16(DEFAULT_RCBA + RCBA_D30IR, 0x3210);
153         write16(DEFAULT_RCBA + RCBA_D29IR, 0x3237);
154         write16(DEFAULT_RCBA + RCBA_D28IR, 0x3214);
155
156         /* Setup sata mode */
157         pci_write_config8(PCI_DEV(0, 0x1F, 2), SATA_MAP, (SATA_MODE_AHCI << 6) | (0 << 0));
158 }
159
160 void main(unsigned long bist)
161 {
162         /* int boot_mode = 0; */
163
164         static const struct mem_controller mch[] = {
165                 {
166                         .node_id = 0,
167                         .f0 = PCI_DEV(0, 0x00, 0),
168                         .f1 = PCI_DEV(0, 0x00, 1),
169                         .f2 = PCI_DEV(0, 0x00, 2),
170                         .f3 = PCI_DEV(0, 0x00, 3),
171                         .channel0 = { (0xa<<3)|3, (0xa<<3)|2, (0xa<<3)|1, (0xa<<3)|0 },
172                         .channel1 = { (0xa<<3)|7, (0xa<<3)|6, (0xa<<3)|5, (0xa<<3)|4 },
173                 }
174         };
175
176         if (bist == 0) {
177                 enable_lapic();
178         }
179
180         /* Setup the console */
181         i3100_enable_superio();
182         i3100_enable_serial(0x4E, I3100_SP1, CONFIG_TTYS0_BASE);
183         uart_init();
184         console_init();
185
186         /* Halt if there was a built in self test failure */
187         report_bist_failure(bist);
188
189         /* Perform early board specific init */
190         early_config();
191
192         /* Prevent the TCO timer from rebooting us */
193         i3100_halt_tco_timer();
194
195         /* Enable SPD ROMs and DDR-II DRAM */
196         enable_smbus();
197
198         /* Enable SpeedStep and automatic thermal throttling */
199         {
200                 msr_t msr;
201                 u16 perf;
202
203                 msr = rdmsr(IA32_MISC_ENABLES);
204                 msr.lo |= (1 << 3) | (1 << 16);
205                 wrmsr(IA32_MISC_ENABLES, msr);
206
207                 /* Set CPU frequency/voltage to maximum */
208
209                 /* Read performance status register and keep
210                  * bits 47:32, where BUS_RATIO_MAX and VID_MAX
211                  * are encoded
212                  */
213                 msr = rdmsr(IA32_PERF_STS);
214                 perf = msr.hi & 0x0000ffff;
215
216                 /* Write VID_MAX & BUS_RATIO_MAX to
217                  * performance control register
218                  */
219                 msr = rdmsr(IA32_PERF_CTL);
220                 msr.lo &= 0xffff0000;
221                 msr.lo |= perf;
222                 wrmsr(IA32_PERF_CTL, msr);
223         }
224
225         /* Initialize memory */
226         sdram_initialize(ARRAY_SIZE(mch), mch);
227 }
228