blob: 16971fc44f8d4d9b007aa03ebb234146605f3616 [file] [log] [blame]
Sven Schnelled8129f92011-04-20 09:12:17 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org>
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// __PRE_RAM__ means: use "unsigned" for device, not a struct.
24
25#include <stdint.h>
26#include <string.h>
27#include <arch/io.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000028#include <device/pci_def.h>
29#include <device/pnp_def.h>
30#include <cpu/x86/lapic.h>
31#include <lib.h>
Paul Menzelac6ea042013-04-29 23:21:07 +020032#include <cbmem.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000033#include <pc80/mc146818rtc.h>
34#include <console/console.h>
Sven Schnelled8129f92011-04-20 09:12:17 +000035#include <cpu/x86/bist.h>
36#include "northbridge/intel/i945/i945.h"
37#include "northbridge/intel/i945/raminit.h"
38#include "southbridge/intel/i82801gx/i82801gx.h"
39#include "dock.h"
40
41void setup_ich7_gpios(void)
42{
43 printk(BIOS_DEBUG, " GPIOS...");
44
45 /* T60 GPIO:
46 6: LEGACYIO#
47 7: BDC_PRESENCE#
48 8: H8_WAKE#
49 10: MDI_DETECT
50 12: H8SCI#
51 14: CPUSB#
52 15: CPPE#
53 25: MDC_KILL#
54 27: EXC_PWR_CTRL
55 28: EXC_AUX_CTRL
56 35: CLKREQ_SATA#
57 36: PLANARID0
58 37: PLANARID1
59 38: PLANARID2
60 39: PLANARID3
61 */
62 outl(0x1f48f7c2, DEFAULT_GPIOBASE + 0x00); /* GPIO_USE_SEL */
63 outl(0xe0e0ffc3, DEFAULT_GPIOBASE + 0x04); /* GP_IO_SEL */
64 outl(0xfbfefb7d, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */
65 /* Output Control Registers */
66 outl(0x00040000, DEFAULT_GPIOBASE + 0x18); /* GPO_BLINK */
67 /* Input Control Registers */
68 outl(0x000039ff, DEFAULT_GPIOBASE + 0x2c); /* GPI_INV */
69 outl(0x000100f0, DEFAULT_GPIOBASE + 0x30); /* GPIO_USE_SEL2 */
70 outl(0x000000f1, DEFAULT_GPIOBASE + 0x34); /* GP_IO_SEL2 */
71 outl(0x000300a3, DEFAULT_GPIOBASE + 0x38); /* GP_LVL2 */
72}
73
74static void ich7_enable_lpc(void)
75{
76 // Enable Serial IRQ
77 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x64, 0xd0);
78 // decode range
79 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x80, 0x0210);
80 // decode range
81 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x82, 0x1f0d);
82
83 /* range 0x1600 - 0x167f */
84 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x84, 0x1601);
85 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x86, 0x007c);
86
87 /* range 0x15e0 - 0x10ef */
88 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x88, 0x15e1);
89 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8a, 0x000c);
90
91 /* range 0x1680 - 0x169f */
92 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8c, 0x1681);
93 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8e, 0x001c);
94}
95
96static void early_superio_config(void)
97{
98 int timeout = 100000;
99 device_t dev = PNP_DEV(0x2e, 3);
100
101 pnp_write_config(dev, 0x29, 0xa0);
102
103 while(!(pnp_read_config(dev, 0x29) & 0x10) && timeout--)
104 udelay(1000);
105
106 /* Enable COM1 */
107 pnp_set_logical_device(dev);
108 pnp_set_iobase(dev, PNP_IDX_IO0, 0x3f8);
109 pnp_set_enable(dev, 1);
110}
111
112static void rcba_config(void)
113{
114 /* Set up virtual channel 0 */
115 RCBA32(0x0014) = 0x80000001;
116 RCBA32(0x001c) = 0x03128010;
117
118 /* Device 1f interrupt pin register */
119 RCBA32(0x3100) = 0x00001230;
120 RCBA32(0x3108) = 0x40004321;
121
122 /* PCIe Interrupts */
123 RCBA32(0x310c) = 0x00004321;
124 /* HD Audio Interrupt */
125 RCBA32(0x3110) = 0x00000002;
126
127 /* dev irq route register */
128 RCBA16(0x3140) = 0x1007;
129 RCBA16(0x3142) = 0x0076;
130 RCBA16(0x3144) = 0x3210;
131 RCBA16(0x3146) = 0x7654;
132 RCBA16(0x3148) = 0x0010;
133
134 /* Enable IOAPIC */
135 RCBA8(0x31ff) = 0x03;
136
137 /* Enable upper 128bytes of CMOS */
138 RCBA32(0x3400) = (1 << 2);
139
140 /* Disable unused devices */
141 RCBA32(0x3418) = FD_PCIE6 | FD_PCIE5 | FD_INTLAN | FD_ACMOD | FD_ACAUD;
142 RCBA32(0x3418) |= (1 << 0); // Required.
143
144 /* Set up I/O Trap #0 for 0xfe00 (SMIC) */
145 RCBA32(0x1e84) = 0x00020001;
146 RCBA32(0x1e80) = 0x0000fe01;
147
148 /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */
149 RCBA32(0x1e9c) = 0x000200f0;
150 RCBA32(0x1e98) = 0x000c0801;
151}
152
153static void early_ich7_init(void)
154{
155 uint8_t reg8;
156 uint32_t reg32;
157
158 // program secondary mlt XXX byte?
159 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
160
161 // reset rtc power status
162 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
163 reg8 &= ~(1 << 2);
164 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
165
166 // usb transient disconnect
167 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
168 reg8 |= (3 << 0);
169 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
170
171 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
172 reg32 |= (1 << 29) | (1 << 17);
173 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
174
175 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
176 reg32 |= (1 << 31) | (1 << 27);
177 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
178
179 RCBA32(0x0088) = 0x0011d000;
180 RCBA16(0x01fc) = 0x060f;
181 RCBA32(0x01f4) = 0x86000040;
182 RCBA32(0x0214) = 0x10030549;
183 RCBA32(0x0218) = 0x00020504;
184 RCBA8(0x0220) = 0xc5;
185 reg32 = RCBA32(0x3410);
186 reg32 |= (1 << 6);
187 RCBA32(0x3410) = reg32;
188 reg32 = RCBA32(0x3430);
189 reg32 &= ~(3 << 0);
190 reg32 |= (1 << 0);
191 RCBA32(0x3430) = reg32;
192 RCBA32(0x3418) |= (1 << 0);
193 RCBA16(0x0200) = 0x2008;
194 RCBA8(0x2027) = 0x0d;
195 RCBA16(0x3e08) |= (1 << 7);
196 RCBA16(0x3e48) |= (1 << 7);
197 RCBA32(0x3e0e) |= (1 << 7);
198 RCBA32(0x3e4e) |= (1 << 7);
199
200 // next step only on ich7m b0 and later:
201 reg32 = RCBA32(0x2034);
202 reg32 &= ~(0x0f << 16);
203 reg32 |= (5 << 16);
204 RCBA32(0x2034) = reg32;
205}
206
Sven Schnelled8129f92011-04-20 09:12:17 +0000207void main(unsigned long bist)
208{
209 u32 reg32;
Sven Schnelleb5381102011-10-15 17:31:01 +0200210 int boot_mode = 0, dock_err;
Paul Menzelac6ea042013-04-29 23:21:07 +0200211 int cbmem_was_initted;
Sven Schnelled8129f92011-04-20 09:12:17 +0000212 const u8 spd_addrmap[2 * DIMM_SOCKETS] = { 0x50, 0x52, 0x51, 0x53 };
213
214 if (bist == 0)
215 enable_lapic();
216
217 /* Force PCIRST# */
218 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
219 udelay(200 * 1000);
220 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
221
222 ich7_enable_lpc();
223
Sven Schnelleb5381102011-10-15 17:31:01 +0200224 /* We want early GPIO setup, to be able to detect legacy I/O module */
225 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
226 /* Enable GPIOs */
227 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10);
228 setup_ich7_gpios();
Sven Schnelled8129f92011-04-20 09:12:17 +0000229
Sven Schnelleb5381102011-10-15 17:31:01 +0200230 dock_err = dlpc_init();
231
232 /* We prefer Legacy I/O module over docking */
233 if (legacy_io_present()) {
234 legacy_io_init();
235 early_superio_config();
236 } else if (!dock_err && dock_present()) {
Sven Schnelled8129f92011-04-20 09:12:17 +0000237 dock_connect();
238 early_superio_config();
Sven Schnelled8129f92011-04-20 09:12:17 +0000239 }
240
Sven Schnelleb5381102011-10-15 17:31:01 +0200241 /* Setup the console */
Sven Schnelled8129f92011-04-20 09:12:17 +0000242 console_init();
243
244 /* Halt if there was a built in self test failure */
245 report_bist_failure(bist);
246
247 if (MCHBAR16(SSKPD) == 0xCAFE) {
248 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
249 outb(0x6, 0xcf9);
250 while (1) asm("hlt");
251 }
252
253 /* Perform some early chipset initialization required
254 * before RAM initialization can work
255 */
256 i945_early_initialization();
257
258 /* Read PM1_CNT */
259 reg32 = inl(DEFAULT_PMBASE + 0x04);
260 printk(BIOS_DEBUG, "PM1_CNT: %08x\n", reg32);
261 if (((reg32 >> 10) & 7) == 5) {
262#if CONFIG_HAVE_ACPI_RESUME
263 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
264 boot_mode = 2;
265 /* Clear SLP_TYPE. This will break stage2 but
266 * we care for that when we get there.
267 */
268 outl(reg32 & ~(7 << 10), DEFAULT_PMBASE + 0x04);
269
270#else
271 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
272#endif
273 }
274
275 /* Enable SPD ROMs and DDR-II DRAM */
276 enable_smbus();
277
278#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
279 dump_spd_registers();
280#endif
281
282 sdram_initialize(boot_mode, spd_addrmap);
283
284 /* Perform some initialization that must run before stage2 */
285 early_ich7_init();
286
287 /* This should probably go away. Until now it is required
288 * and mainboard specific
289 */
290 rcba_config();
291
292 /* Chipset Errata! */
293 fixup_i945_errata();
294
295 /* Initialize the internal PCIe links before we go into stage2 */
296 i945_late_initialization();
297
298#if !CONFIG_HAVE_ACPI_RESUME
299#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
300#if CONFIG_DEBUG_RAM_SETUP
301 sdram_dump_mchbar_registers();
302
303 {
304 /* This will not work if TSEG is in place! */
305 u32 tom = pci_read_config32(PCI_DEV(0,2,0), 0x5c);
306
307 printk(BIOS_DEBUG, "TOM: 0x%08x\n", tom);
308 ram_check(0x00000000, 0x000a0000);
309 ram_check(0x00100000, tom);
310 }
311#endif
312#endif
313#endif
314
315 MCHBAR16(SSKPD) = 0xCAFE;
316
Paul Menzelac6ea042013-04-29 23:21:07 +0200317 cbmem_was_initted = !cbmem_initialize();
Sven Schnelled8129f92011-04-20 09:12:17 +0000318
Paul Menzelac6ea042013-04-29 23:21:07 +0200319#if CONFIG_HAVE_ACPI_RESUME
Sven Schnelled8129f92011-04-20 09:12:17 +0000320 /* If there is no high memory area, we didn't boot before, so
321 * this is not a resume. In that case we just create the cbmem toc.
322 */
Paul Menzelac6ea042013-04-29 23:21:07 +0200323 if ((boot_mode == 2) && cbmem_was_initted) {
Sven Schnelled8129f92011-04-20 09:12:17 +0000324 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
325
326 /* copy 1MB - 64K to high tables ram_base to prevent memory corruption
327 * through stage 2. We could keep stuff like stack and heap in high tables
328 * memory completely, but that's a wonderful clean up task for another
329 * day.
330 */
331 if (resume_backup_memory)
332 memcpy(resume_backup_memory, (void *)CONFIG_RAMBASE, HIGH_MEMORY_SAVE);
333
334 /* Magic for S3 resume */
Sven Schnelled8c68a92011-06-15 09:26:34 +0200335 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, SKPAD_ACPI_S3_MAGIC);
Sven Schnelled8129f92011-04-20 09:12:17 +0000336 }
337#endif
Paul Menzelac6ea042013-04-29 23:21:07 +0200338
339#if CONFIG_CONSOLE_CBMEM
340 /* Keep this the last thing this function does. */
341 cbmemc_reinit();
342#endif
Sven Schnelled8129f92011-04-20 09:12:17 +0000343}