blob: 2431d946f270f7bcc2d0758882660e4b52e6a99a [file] [log] [blame]
Aaron Durbinf6933a62012-10-30 09:09:39 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2010 coresystems GmbH
5 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdint.h>
22#include <string.h>
23#include <lib.h>
24#include <timestamp.h>
25#include <arch/io.h>
26#include <arch/romcc_io.h>
27#include <device/pci_def.h>
28#include <device/pnp_def.h>
29#include <cpu/x86/lapic.h>
30#include <pc80/mc146818rtc.h>
31#include <cbmem.h>
32#include <console/console.h>
33#include "northbridge/intel/haswell/haswell.h"
34#include "northbridge/intel/haswell/raminit.h"
35#include "southbridge/intel/lynxpoint/pch.h"
36#include "southbridge/intel/lynxpoint/gpio.h"
37#include <arch/cpu.h>
38#include <cpu/x86/bist.h>
39#include <cpu/x86/msr.h>
40#include "gpio.h"
41#if CONFIG_CHROMEOS
42#include <vendorcode/google/chromeos/chromeos.h>
43#endif
44
45static void pch_enable_lpc(void)
46{
47 device_t dev = PCH_LPC_DEV;
48
49 /* Set COM1/COM2 decode range */
50 pci_write_config16(dev, LPC_IO_DEC, 0x0010);
51
52 /* Enable SuperIO + COM1 + PS/2 Keyboard/Mouse */
53 u16 lpc_config = CNF1_LPC_EN | CNF2_LPC_EN | COMA_LPC_EN | KBC_LPC_EN;
54 pci_write_config16(dev, LPC_EN, lpc_config);
55}
56
57static void rcba_config(void)
58{
59 u32 reg32;
60
61 /*
62 * GFX INTA -> PIRQA (MSI)
63 * D28IP_P1IP WLAN INTA -> PIRQB
64 * D28IP_P4IP ETH0 INTB -> PIRQC
65 * D29IP_E1P EHCI1 INTA -> PIRQD
66 * D26IP_E2P EHCI2 INTA -> PIRQE
67 * D31IP_SIP SATA INTA -> PIRQF (MSI)
68 * D31IP_SMIP SMBUS INTB -> PIRQG
69 * D31IP_TTIP THRT INTC -> PIRQH
70 * D27IP_ZIP HDA INTA -> PIRQG (MSI)
71 */
72
73 /* Device interrupt pin register (board specific) */
74 RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
75 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
76 RCBA32(D30IP) = (NOINT << D30IP_PIP);
77 RCBA32(D29IP) = (INTA << D29IP_E1P);
78 RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) |
79 (INTB << D28IP_P4IP);
80 RCBA32(D27IP) = (INTA << D27IP_ZIP);
81 RCBA32(D26IP) = (INTA << D26IP_E2P);
82 RCBA32(D25IP) = (NOINT << D25IP_LIP);
83 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
84
85 /* Device interrupt route registers */
86 DIR_ROUTE(D31IR, PIRQF, PIRQG, PIRQH, PIRQA);
87 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
88 DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE);
89 DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB);
90 DIR_ROUTE(D26IR, PIRQE, PIRQF, PIRQG, PIRQH);
91 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
92 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
93
94 /* Enable IOAPIC (generic) */
95 RCBA16(OIC) = 0x0100;
96 /* PCH BWG says to read back the IOAPIC enable register */
97 (void) RCBA16(OIC);
98
99 /* Disable unused devices (board specific) */
100 reg32 = RCBA32(FD);
101 reg32 |= PCH_DISABLE_ALWAYS;
102 RCBA32(FD) = reg32;
103}
104
105// FIXME, this function is generic code that should go to sb/... or
106// nb/../early_init.c
107static void early_pch_init(void)
108{
109 u8 reg8;
110
111 // reset rtc power status
112 reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4);
113 reg8 &= ~(1 << 2);
114 pci_write_config8(PCH_LPC_DEV, 0xa4, reg8);
115}
116
117void main(unsigned long bist)
118{
119 int boot_mode = 0;
120 int cbmem_was_initted;
121 u32 pm1_cnt;
122 u16 pm1_sts;
123
124#if CONFIG_COLLECT_TIMESTAMPS
125 tsc_t start_romstage_time;
126 tsc_t before_dram_time;
127 tsc_t after_dram_time;
128 tsc_t base_time = {
129 .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc),
130 .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0)
131 };
132#endif
133 struct pei_data pei_data = {
134 pei_version: PEI_VERSION,
135 mchbar: DEFAULT_MCHBAR,
136 dmibar: DEFAULT_DMIBAR,
137 epbar: DEFAULT_EPBAR,
138 pciexbar: CONFIG_MMCONF_BASE_ADDRESS,
139 smbusbar: SMBUS_IO_BASE,
140 wdbbar: 0x4000000,
141 wdbsize: 0x1000,
142 hpet_address: HPET_ADDR,
143 rcba: DEFAULT_RCBA,
144 pmbase: DEFAULT_PMBASE,
145 gpiobase: DEFAULT_GPIOBASE,
Aaron Durbin8256a9b2012-11-29 17:18:53 -0600146 temp_mmio_base: 0xfed08000,
Aaron Durbinf6933a62012-10-30 09:09:39 -0500147 system_type: 0, // 0 Mobile, 1 Desktop/Server
148 tseg_size: CONFIG_SMM_TSEG_SIZE,
Aaron Durbin68724fd2012-12-07 09:47:16 -0600149 spd_addresses: { 0xa0, 0xa2, 0xa4, 0xa6 },
Aaron Durbinf6933a62012-10-30 09:09:39 -0500150 ec_present: 0,
151 // 0 = leave channel enabled
152 // 1 = disable dimm 0 on channel
153 // 2 = disable dimm 1 on channel
154 // 3 = disable dimm 0+1 on channel
Aaron Durbin68724fd2012-12-07 09:47:16 -0600155 dimm_channel0_disabled: 0,
156 dimm_channel1_disabled: 0,
Aaron Durbinf6933a62012-10-30 09:09:39 -0500157 max_ddr3_freq: 1600,
158 usb_port_config: {
Aaron Durbin68724fd2012-12-07 09:47:16 -0600159 { 1, 0, 0x0040 }, /* P0: Back USB3 port (OC0) */
160 { 1, 0, 0x0040 }, /* P1: Back USB3 port (OC0) */
161 { 1, 1, 0x0040 }, /* P2: Flex Port on bottom (OC1) */
162 { 1, 8, 0x0040 }, /* P3: Docking connector (no OC) */
163 { 1, 8, 0x0040 }, /* P4: Mini PCIE (no OC) */
164 { 1, 1, 0x0040 }, /* P5: USB eSATA header (OC1) */
165 { 1, 3, 0x0040 }, /* P6: Front Header J8H2 (OC3) */
166 { 1, 3, 0x0040 }, /* P7: Front Header J8H2 (OC3) */
167 { 1, 4, 0x0040 }, /* P8: USB/LAN Jack (OC4) */
168 { 1, 4, 0x0040 }, /* P9: USB/LAN Jack (OC4) */
169 { 1, 5, 0x0040 }, /* P10: Front Header J7H3 (OC5) */
170 { 1, 5, 0x0040 }, /* P11: Front Header J7H3 (OC5) */
171 { 1, 6, 0x0040 }, /* P12: USB/DP Jack (OC6) */
172 { 1, 6, 0x0040 }, /* P13: USB/DP Jack (OC6) */
Aaron Durbinf6933a62012-10-30 09:09:39 -0500173 },
174 };
175
176#if CONFIG_COLLECT_TIMESTAMPS
177 start_romstage_time = rdtsc();
178#endif
179
180 if (bist == 0)
181 enable_lapic();
182
183 pch_enable_lpc();
184
185 /* Enable GPIOs */
186 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
187 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
188 setup_pch_gpios(&graysreef_gpio_map);
189
190 /* Early Console setup */
191 console_init();
192
193 /* Halt if there was a built in self test failure */
194 report_bist_failure(bist);
195
Aaron Durbin30c39002012-11-29 17:21:51 -0600196 /*
197 * FIXME: MCHBAR isn't setup yet. It's setup in
198 * haswell_early_initialization().
199 */
Aaron Durbinf6933a62012-10-30 09:09:39 -0500200 if (MCHBAR16(SSKPD) == 0xCAFE) {
201 printk(BIOS_DEBUG, "soft reset detected\n");
202 boot_mode = 1;
203
204 /* System is not happy after keyboard reset... */
205 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
206 outb(0x6, 0xcf9);
207 while (1) {
208 hlt();
209 }
210 }
211
212 /* Perform some early chipset initialization required
213 * before RAM initialization can work
214 */
215 haswell_early_initialization(HASWELL_MOBILE);
216 printk(BIOS_DEBUG, "Back from haswell_early_initialization()\n");
217
218 /* Check PM1_STS[15] to see if we are waking from Sx */
219 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
220
221 /* Read PM1_CNT[12:10] to determine which Sx state */
222 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
223
224 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
225#if CONFIG_HAVE_ACPI_RESUME
226 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
227 boot_mode = 2;
228 /* Clear SLP_TYPE. This will break stage2 but
229 * we care for that when we get there.
230 */
231 outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT);
232#else
233 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
234#endif
235 }
236
237 post_code(0x38);
238 /* Enable SPD ROMs and DDR-III DRAM */
239 enable_smbus();
240
241 /* Prepare USB controller early in S3 resume */
242 if (boot_mode == 2)
243 enable_usb_bar();
244
245 post_code(0x3a);
246 pei_data.boot_mode = boot_mode;
247#if CONFIG_COLLECT_TIMESTAMPS
248 before_dram_time = rdtsc();
249#endif
250 sdram_initialize(&pei_data);
251
Aaron Durbinf6933a62012-10-30 09:09:39 -0500252#if CONFIG_COLLECT_TIMESTAMPS
253 after_dram_time = rdtsc();
254#endif
255 post_code(0x3b);
256 /* Perform some initialization that must run before stage2 */
257 early_pch_init();
258 post_code(0x3c);
259
260 /* This should probably go away. Until now it is required
261 * and mainboard specific
262 */
263 rcba_config();
264 post_code(0x3d);
265
266 quick_ram_check();
267 post_code(0x3e);
268
269 MCHBAR16(SSKPD) = 0xCAFE;
270#if CONFIG_EARLY_CBMEM_INIT
271 cbmem_was_initted = !cbmem_initialize();
272#else
273 cbmem_was_initted = cbmem_reinit((uint64_t) (get_top_of_ram()
274 - HIGH_MEMORY_SIZE));
275#endif
276
277#if CONFIG_HAVE_ACPI_RESUME
278 /* If there is no high memory area, we didn't boot before, so
279 * this is not a resume. In that case we just create the cbmem toc.
280 */
281
282 *(u32 *)CBMEM_BOOT_MODE = 0;
283 *(u32 *)CBMEM_RESUME_BACKUP = 0;
284
285 if ((boot_mode == 2) && cbmem_was_initted) {
286 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
287 if (resume_backup_memory) {
288 *(u32 *)CBMEM_BOOT_MODE = boot_mode;
289 *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory;
290 }
291 /* Magic for S3 resume */
292 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d);
293 } else if (boot_mode == 2) {
294 /* Failed S3 resume, reset to come up cleanly */
295 outb(0x6, 0xcf9);
296 while (1) {
297 hlt();
298 }
299 } else {
300 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
301 }
302#endif
303 post_code(0x3f);
304#if CONFIG_CHROMEOS
305 init_chromeos(boot_mode);
306#endif
307#if CONFIG_COLLECT_TIMESTAMPS
308 timestamp_init(base_time);
309 timestamp_add(TS_START_ROMSTAGE, start_romstage_time );
310 timestamp_add(TS_BEFORE_INITRAM, before_dram_time );
311 timestamp_add(TS_AFTER_INITRAM, after_dram_time );
312 timestamp_add_now(TS_END_ROMSTAGE);
313#endif
314#if CONFIG_CONSOLE_CBMEM
315 /* Keep this the last thing this function does. */
316 cbmemc_reinit();
317#endif
318}