blob: 92dfe7402d1778c4056ec308e93e9844c32bee62 [file] [log] [blame]
Mono9b908242014-03-02 18:40:36 +01001/*
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.
Mono9b908242014-03-02 18:40:36 +010016 */
17
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +020018/* __PRE_RAM__ means: use "unsigned" for device, not a struct. */
Mono9b908242014-03-02 18:40:36 +010019
20#include <stdint.h>
21#include <string.h>
22#include <arch/io.h>
23#include <device/pci_def.h>
24#include <device/pnp_def.h>
Edward O'Callaghancea45572014-11-19 12:08:24 +110025#include <cpu/intel/romstage.h>
Mono9b908242014-03-02 18:40:36 +010026#include <cpu/x86/lapic.h>
27#include <lib.h>
28#include <cbmem.h>
29#include <timestamp.h>
30#include <pc80/mc146818rtc.h>
31#include <console/console.h>
32#include <cpu/x86/bist.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010033#include <halt.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110034#include <northbridge/intel/i945/i945.h>
35#include <northbridge/intel/i945/raminit.h>
36#include <southbridge/intel/i82801gx/i82801gx.h>
Mono9b908242014-03-02 18:40:36 +010037
Mono9b908242014-03-02 18:40:36 +010038static void ich7_enable_lpc(void)
39{
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +020040 /* Enable Serial IRQ */
Mono9b908242014-03-02 18:40:36 +010041 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x64, 0xd0);
42
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +020043 /* I/O Decode Ranges
44 * X60: 0x0210 == 00000010 00010000
45 * Macbook21: 0x0010 == 00000000 00010000
46 * Bit 9:8 LPT Decode Range. This field determines which range to
47 * decode for the LPT Port.
48 * 00 = 378h - 37Fh and 778h - 77Fh
49 * 10 = 3BCh - 3BEh and 7BCh - 7BEh
50 */
Mono9b908242014-03-02 18:40:36 +010051 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x80, 0x0010);
52
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +020053 /* LPC_EN--LPC I/F Enables Register
54 * X60: 0x1f0d == 00011111 00001101
55 * Macbook21: 0x3807 == 00111000 00000111
56 * Bit 13 CNF2_LPC_EN -- R/W. Microcontroller Enable # 2.
57 * 0 = Disable.
58 * 1 = Enables the decoding of the I/O locations 4Eh and 4Fh
59 * to the LPC interface. This range is used for a
60 * microcontroller.
61 * Bit 12 CNF1_LPC_EN -- R/W. Super I/O Enable.
62 * 0 = Disable.
63 * 1 = Enables the decoding of the I/O locations 2Eh and 2Fh
64 * to the LPC interface. This range is used for
65 * Super I/O devices.
66 * Bit 11 MC_LPC_EN -- R/W. Microcontroller Enable # 1.
67 * 0 = Disable.
68 * 1 = Enables the decoding of the I/O locations 62h and 66h
69 * to the LPC interface. This range is used for a
70 * microcontroller.
71 * Bit 10 KBC_LPC_EN -- R/W. Keyboard Enable.
72 * 0 = Disable.
73 * 1 = Enables the decoding of the I/O locations 60h and 64h
74 * to the LPC interface. This range is used for a
75 * microcontroller.
76 * Bit 9 GAMEH_LPC_EN -- R/W. High Gameport Enable
77 * 0 = Disable.
78 * 1 = Enables the decoding of the I/O locations 208h to 20Fh
79 * to the LPC interface. This range is used for a gameport.
80 * Bit 8 GAMEL_LPC_EN -- R/W. Low Gameport Enable
81 * 0 = Disable.
82 * 1 = Enables the decoding of the I/O locations 200h to 207h
83 * to the LPC interface. This range is used for a gameport.
84 * Bit 3 FDD_LPC_EN -- R/W. Floppy Drive Enable
85 * 0 = Disable.
86 * 1 = Enables the decoding of the FDD range to the LPC
87 * interface. This range is selected in the LPC_FDD/LPT
88 * Decode Range Register (D31:F0:80h, bit 12).
89 * Bit 2 LPT_LPC_EN -- R/W. Parallel Port Enable
90 * 0 = Disable.
91 * 1 = Enables the decoding of the LPT range to the LPC
92 * interface. This range is selected in the LPC_FDD/LPT
93 * Decode Range Register (D31:F0:80h, bit 9:8).
94 * Bit 1 COMB_LPC_EN -- R/W. Com Port B Enable
95 * 0 = Disable.
96 * 1 = Enables the decoding of the COMB range to the LPC
97 * interface. This range is selected in the LPC_COM Decode
98 * Range Register (D31:F0:80h, bits 6:4).
99 * Bit 0 COMA_LPC_EN -- R/W. Com Port A Enable
100 * 0 = Disable.
101 * 1 = Enables the decoding of the COMA range to the LPC
102 * interface. This range is selected in the LPC_COM Decode
103 * Range Register (D31:F0:80h, bits 3:2).
104 */
Mono9b908242014-03-02 18:40:36 +0100105 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x82, 0x3807);
106
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +0200107 /* GEN1_DEC, LPC Interface Generic Decode Range 1
108 * X60: 0x1601 0x007c == 00000000 01111100 00010110 00000001
109 * Macbook21: 0x0681 0x000c == 00000000 00001100 00000110 10000001
110 * Bit 31:24 Reserved.
111 * Bit 23:18 Generic I/O Decode Range Address[7:2] Mask: A `1' in any
112 * bit position indicates that any value in the corresponding
113 * address bit in a received cycle will be treated as a
114 * match. The corresponding bit in the Address field, below,
115 * is ignored. The mask is only provided for the lower 6 bits
116 * of the DWord address, allowing for decoding blocks up to
117 * 256 bytes in size.
118 * Bit 17:16 Reserved.
119 * Bit 15:2 Generic I/O Decode Range 1 Base Address (GEN1_BASE). This
120 * address is aligned on a 128-byte boundary, and must have
121 * address lines 31:16 as 0. NOTE: The Intel ICH7 does not
122 * provide decode down to the word or byte level.
123 * Bit 1 Reserved.
124 * Bit 0 Generic Decode Range 1 Enable (GEN1_EN) -- R/W.
125 * 0 = Disable.
126 * 1 = Enable the GEN1 I/O range to be forwarded to the LPC
127 * I/F
128 */
Mono9b908242014-03-02 18:40:36 +0100129 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x84, 0x0681);
130 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x86, 0x000c);
131
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +0200132 /* GEN2_DEC, LPC Interface Generic Decode Range 2
133 * X60: 0x15e1 0x000c == 00000000 00001100 00010101 11100001
134 * Macbook21: 0x1641 0x000c == 00000000 00001100 00010110 01000001
135 */
Mono9b908242014-03-02 18:40:36 +0100136 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x88, 0x1641);
137 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8a, 0x000c);
138
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +0200139 /* GEN3_DEC, LPC Interface Generic Decode Range 3
140 * X60: 0x1681 0x001c == 00000000 00011100 00010110 10000001
141 * Macbook21: 0x0000 0x0000
142 */
143 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8c, 0x0000); /* obsolete, because it writes zeros? */
Mono9b908242014-03-02 18:40:36 +0100144 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8e, 0x0000);
145
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +0200146 /* GEN4_DEC, LPC Interface Generic Decode Range 4
147 * X60: 0x0000 0x0000
148 * Macbook21: 0x0301 0x001c == 00000000 00011100 00000011 00000001
149 */
Mono9b908242014-03-02 18:40:36 +0100150 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x90, 0x0301);
151 pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x92, 0x001c);
152}
153
154static void rcba_config(void)
155{
156 /* V0CTL Virtual Channel 0 Resource Control */
157 RCBA32(0x0014) = 0x80000001;
158 /* V1CAP Virtual Channel 1 Resource Capability */
159 RCBA32(0x001c) = 0x03128010;
160
161 /* Device 1f interrupt pin register */
162 RCBA32(0x3100) = 0x00042210;
163 RCBA32(0x3108) = 0x10004321;
164
165 /* PCIe Interrupts */
166 RCBA32(0x310c) = 0x00214321;
167 /* HD Audio Interrupt */
168 RCBA32(0x3110) = 0x00000001;
169
170 /* dev irq route register */
171 RCBA16(0x3140) = 0x0232;
172 RCBA16(0x3142) = 0x3246;
173 RCBA16(0x3144) = 0x0235;
174 RCBA16(0x3146) = 0x3201;
175 RCBA16(0x3148) = 0x3216;
176
177 /* Enable IOAPIC */
178 RCBA8(0x31ff) = 0x03;
179
Mono9b908242014-03-02 18:40:36 +0100180 /* Disable unused devices */
181 RCBA32(0x3418) = FD_PCIE6 | FD_PCIE5 | FD_PCIE4 | FD_PCIE3 | FD_INTLAN | FD_ACMOD | FD_ACAUD;
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +0200182 RCBA32(0x3418) |= (1 << 0); /* Required. */
Mono9b908242014-03-02 18:40:36 +0100183
184 /* Set up I/O Trap #0 for 0xfe00 (SMIC) */
Mono9b908242014-03-02 18:40:36 +0100185
186 /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */
187 RCBA32(0x1e9c) = 0x000200f0;
188 RCBA32(0x1e98) = 0x000c0801;
189}
190
191static void early_ich7_init(void)
192{
193 uint8_t reg8;
194 uint32_t reg32;
195
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +0200196 /* program secondary mlt XXX byte? */
Mono9b908242014-03-02 18:40:36 +0100197 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
198
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +0200199 /* reset rtc power status */
Mono9b908242014-03-02 18:40:36 +0100200 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
201 reg8 &= ~(1 << 2);
202 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
203
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +0200204 /* usb transient disconnect */
Mono9b908242014-03-02 18:40:36 +0100205 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
206 reg8 |= (3 << 0);
207 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
208
209 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
210 reg32 |= (1 << 29) | (1 << 17);
211 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
212
213 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
214 reg32 |= (1 << 31) | (1 << 27);
215 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
216
217 RCBA32(0x0088) = 0x0011d000;
218 RCBA16(0x01fc) = 0x060f;
219 RCBA32(0x01f4) = 0x86000040;
220 RCBA32(0x0214) = 0x10030549;
221 RCBA32(0x0218) = 0x00020504;
222 RCBA8(0x0220) = 0xc5;
223 reg32 = RCBA32(0x3410);
224 reg32 |= (1 << 6);
225 RCBA32(0x3410) = reg32;
226 reg32 = RCBA32(0x3430);
227 reg32 &= ~(3 << 0);
228 reg32 |= (1 << 0);
229 RCBA32(0x3430) = reg32;
230 RCBA32(0x3418) |= (1 << 0);
231 RCBA16(0x0200) = 0x2008;
232 RCBA8(0x2027) = 0x0d;
233 RCBA16(0x3e08) |= (1 << 7);
234 RCBA16(0x3e48) |= (1 << 7);
235 RCBA32(0x3e0e) |= (1 << 7);
236 RCBA32(0x3e4e) |= (1 << 7);
237
Elyes HAOUAS571fb1f2016-10-07 12:46:28 +0200238 /* next step only on ich7m b0 and later: */
Mono9b908242014-03-02 18:40:36 +0100239 reg32 = RCBA32(0x2034);
240 reg32 &= ~(0x0f << 16);
241 reg32 |= (5 << 16);
242 RCBA32(0x2034) = reg32;
243}
244
Kyösti Mälkki15fa9922016-06-17 10:00:28 +0300245void mainboard_romstage_entry(unsigned long bist)
Mono9b908242014-03-02 18:40:36 +0100246{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200247 int s3resume = 0;
Mono9b908242014-03-02 18:40:36 +0100248 const u8 spd_addrmap[2 * DIMM_SOCKETS] = { 0x50, 0x51, 0x52, 0x53 };
249
Mono9b908242014-03-02 18:40:36 +0100250 timestamp_init(get_initial_timestamp());
251 timestamp_add_now(TS_START_ROMSTAGE);
252
253 if (bist == 0)
254 enable_lapic();
255
Mono9b908242014-03-02 18:40:36 +0100256 ich7_enable_lpc();
257
258 /* Set up the console */
259 console_init();
260
261 /* Halt if there was a built in self test failure */
262 report_bist_failure(bist);
263
264 if (MCHBAR16(SSKPD) == 0xCAFE) {
265 printk(BIOS_DEBUG,
266 "Soft reset detected, rebooting properly.\n");
267 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100268 halt();
Mono9b908242014-03-02 18:40:36 +0100269 }
270
271 /* Perform some early chipset initialization required
272 * before RAM initialization can work
273 */
274 i945_early_initialization();
275
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200276 s3resume = southbridge_detect_s3_resume();
Mono9b908242014-03-02 18:40:36 +0100277
278 /* Enable SPD ROMs and DDR-II DRAM */
279 enable_smbus();
280
281#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
282 dump_spd_registers();
283#endif
284
285 timestamp_add_now(TS_BEFORE_INITRAM);
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200286 sdram_initialize(s3resume ? 2 : 0, spd_addrmap);
Mono9b908242014-03-02 18:40:36 +0100287 timestamp_add_now(TS_AFTER_INITRAM);
288
289 /* Perform some initialization that must run before stage2 */
290 early_ich7_init();
291
292 /* This should probably go away. Until now it is required
293 * and mainboard specific
294 */
295 rcba_config();
296
297 /* Chipset Errata! */
298 fixup_i945_errata();
299
300 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200301 i945_late_initialization(s3resume);
Mono9b908242014-03-02 18:40:36 +0100302}