8ffe22c168a52869d5c8e531d83c65e6a15018b1
[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 "southbridge/intel/i3100/i3100_early_smbus.c"
38 #include "southbridge/intel/i3100/i3100_early_lpc.c"
39 #include "reset.c"
40 #include "superio/intel/i3100/i3100_early_serial.c"
41 #include "superio/smsc/smscsuperio/smscsuperio_early_serial.c"
42
43 #define DEVPRES_CONFIG  (DEVPRES_D1F0 | DEVPRES_D2F0 | DEVPRES_D3F0)
44 #define DEVPRES1_CONFIG (DEVPRES1_D0F1 | DEVPRES1_D8F0)
45
46 #define IA32_PERF_STS     0x198
47 #define IA32_PERF_CTL     0x199
48 #define MSR_THERM2_CTL    0x19D
49 #define IA32_MISC_ENABLES 0x1A0
50
51 /* SATA */
52 #define SATA_MAP 0x90
53
54 #define SATA_MODE_IDE  0x00
55 #define SATA_MODE_AHCI 0x01
56
57 /* RCBA registers */
58 #define RCBA 0xF0
59 #define DEFAULT_RCBA 0xFEA00000
60
61 #define RCBA_RPC   0x0224 /* 32 bit */
62
63 #define RCBA_TCTL  0x3000 /*  8 bit */
64
65 #define RCBA_D31IP 0x3100 /* 32 bit */
66 #define RCBA_D30IP 0x3104 /* 32 bit */
67 #define RCBA_D29IP 0x3108 /* 32 bit */
68 #define RCBA_D28IP 0x310C /* 32 bit */
69 #define RCBA_D31IR 0x3140 /* 16 bit */
70 #define RCBA_D30IR 0x3142 /* 16 bit */
71 #define RCBA_D29IR 0x3144 /* 16 bit */
72 #define RCBA_D28IR 0x3146 /* 16 bit */
73
74 #define RCBA_RTC   0x3400 /* 32 bit */
75 #define RCBA_HPTC  0x3404 /* 32 bit */
76 #define RCBA_GCS   0x3410 /* 32 bit */
77 #define RCBA_BUC   0x3414 /*  8 bit */
78 #define RCBA_FD    0x3418 /* 32 bit */
79 #define RCBA_PRC   0x341C /* 32 bit */
80
81 static inline int spd_read_byte(u16 device, u8 address)
82 {
83         return smbus_read_byte(device, address);
84 }
85
86 #include "northbridge/intel/i3100/raminit.h"
87 #include "cpu/x86/mtrr/earlymtrr.c"
88 #include "northbridge/intel/i3100/memory_initialized.c"
89 #include "northbridge/intel/i3100/raminit.c"
90 #include "lib/generic_sdram.c"
91 #include "northbridge/intel/i3100/reset_test.c"
92 #include "debug.c"
93
94 static void early_config(void)
95 {
96         u32 gcs, rpc, fd;
97
98         /* Enable RCBA */
99         pci_write_config32(PCI_DEV(0, 0x1F, 0), RCBA, DEFAULT_RCBA | 1);
100
101         /* Disable watchdog */
102         gcs = read32(DEFAULT_RCBA + RCBA_GCS);
103         gcs |= (1 << 5); /* No reset */
104         write32(DEFAULT_RCBA + RCBA_GCS, gcs);
105
106         /* Configure PCIe port B as 4x */
107         rpc = read32(DEFAULT_RCBA + RCBA_RPC);
108         rpc |= (3 << 0);
109         write32(DEFAULT_RCBA + RCBA_RPC, rpc);
110
111         /* Disable Modem, Audio, PCIe ports 2/3/4 */
112         fd = read32(DEFAULT_RCBA + RCBA_FD);
113         fd |= (1 << 19) | (1 << 18) | (1 << 17) | (1 << 6) | (1 << 5);
114         write32(DEFAULT_RCBA + RCBA_FD, fd);
115
116         /* Enable HPET */
117         write32(DEFAULT_RCBA + RCBA_HPTC, (1 << 7));
118
119         /* Improve interrupt routing
120          * D31:F2 SATA        INTB# -> PIRQD
121          * D31:F3 SMBUS       INTB# -> PIRQD
122          * D31:F4 CHAP        INTD# -> PIRQA
123          * D29:F0 USB1#1      INTA# -> PIRQH
124          * D29:F1 USB1#2      INTB# -> PIRQD
125          * D29:F7 USB2        INTA# -> PIRQH
126          * D28:F0 PCIe Port 1 INTA# -> PIRQE
127          */
128
129         write16(DEFAULT_RCBA + RCBA_D31IR, 0x0230);
130         write16(DEFAULT_RCBA + RCBA_D30IR, 0x3210);
131         write16(DEFAULT_RCBA + RCBA_D29IR, 0x3237);
132         write16(DEFAULT_RCBA + RCBA_D28IR, 0x3214);
133
134         /* Setup sata mode */
135         pci_write_config8(PCI_DEV(0, 0x1F, 2), SATA_MAP, (SATA_MODE_AHCI << 6) | (0 << 0));
136 }
137
138 void main(unsigned long bist)
139 {
140         /* int boot_mode = 0; */
141
142         static const struct mem_controller mch[] = {
143                 {
144                         .node_id = 0,
145                         .f0 = PCI_DEV(0, 0x00, 0),
146                         .f1 = PCI_DEV(0, 0x00, 1),
147                         .f2 = PCI_DEV(0, 0x00, 2),
148                         .f3 = PCI_DEV(0, 0x00, 3),
149                         .channel0 = { (0xa<<3)|3, (0xa<<3)|2, (0xa<<3)|1, (0xa<<3)|0 },
150                         .channel1 = { (0xa<<3)|7, (0xa<<3)|6, (0xa<<3)|5, (0xa<<3)|4 },
151                 }
152         };
153
154         if (bist == 0) {
155                 enable_lapic();
156         }
157
158         /* Setup the console */
159         i3100_enable_superio();
160         i3100_enable_serial(0x4E, I3100_SP1, CONFIG_TTYS0_BASE);
161         uart_init();
162         console_init();
163
164         /* Halt if there was a built in self test failure */
165         report_bist_failure(bist);
166
167         /* Perform early board specific init */
168         early_config();
169
170         /* Prevent the TCO timer from rebooting us */
171         i3100_halt_tco_timer();
172
173         /* Enable SPD ROMs and DDR-II DRAM */
174         enable_smbus();
175
176         /* Enable SpeedStep and automatic thermal throttling */
177         {
178                 msr_t msr;
179                 u16 perf;
180
181                 msr = rdmsr(IA32_MISC_ENABLES);
182                 msr.lo |= (1 << 3) | (1 << 16);
183                 wrmsr(IA32_MISC_ENABLES, msr);
184
185                 /* Set CPU frequency/voltage to maximum */
186
187                 /* Read performance status register and keep
188                  * bits 47:32, where BUS_RATIO_MAX and VID_MAX
189                  * are encoded
190                  */
191                 msr = rdmsr(IA32_PERF_STS);
192                 perf = msr.hi & 0x0000ffff;
193
194                 /* Write VID_MAX & BUS_RATIO_MAX to
195                  * performance control register
196                  */
197                 msr = rdmsr(IA32_PERF_CTL);
198                 msr.lo &= 0xffff0000;
199                 msr.lo |= perf;
200                 wrmsr(IA32_PERF_CTL, msr);
201         }
202
203         /* Initialize memory */
204         sdram_initialize(ARRAY_SIZE(mch), mch);
205 }
206