blob: 45cf7fef2a9209d66da45fcb19f20cd1846db289 [file] [log] [blame]
Stefan Reinauera7198b32012-12-11 16:00:47 -08001/*
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>
Hung-Te Line29e2ff2013-01-18 16:50:25 +080025#include <arch/byteorder.h>
Stefan Reinauera7198b32012-12-11 16:00:47 -080026#include <arch/io.h>
Stefan Reinauera7198b32012-12-11 16:00:47 -080027#include <device/pci_def.h>
28#include <device/pnp_def.h>
29#include <cpu/x86/lapic.h>
30#include <pc80/mc146818rtc.h>
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +030031#include <arch/acpi.h>
Stefan Reinauera7198b32012-12-11 16:00:47 -080032#include <cbmem.h>
33#include <console/console.h>
34#include "northbridge/intel/sandybridge/sandybridge.h"
35#include "northbridge/intel/sandybridge/raminit.h"
36#include "southbridge/intel/bd82x6x/pch.h"
37#include "southbridge/intel/bd82x6x/gpio.h"
38#include <arch/cpu.h>
39#include <cpu/x86/bist.h>
40#include <cpu/x86/msr.h>
41#include "gpio.h"
42#if CONFIG_CHROMEOS
43#include <vendorcode/google/chromeos/chromeos.h>
44#endif
45#include <cbfs.h>
46#include "ec/compal/ene932/ec.h"
47
48static void pch_enable_lpc(void)
49{
50 /* Parrot EC Decode Range Port60/64, Port62/66 */
51 /* Enable EC, PS/2 Keyboard/Mouse */
52 pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN);
53
54 /* Map EC_IO decode to the LPC bus */
55 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, (EC_IO & ~3) | 0x00040001);
56
57 /* Map EC registers 68/6C decode to the LPC bus */
58 pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, (68 & ~3) | 0x00040001);
59}
60
61static void rcba_config(void)
62{
63 u32 reg32;
64
65 /*
66 * GFX INTA -> PIRQA (MSI)
67 * D28IP_P2IP WLAN INTA -> PIRQB
68 * D28IP_P3IP ETH0 INTC -> PIRQD
69 * D29IP_E1P EHCI1 INTA -> PIRQE
70 * D26IP_E2P EHCI2 INTA -> PIRQE
71 * D31IP_SIP SATA INTA -> PIRQF (MSI)
72 * D31IP_SMIP SMBUS INTB -> PIRQG
73 * D31IP_TTIP THRT INTC -> PIRQH
74 * D27IP_ZIP HDA INTA -> PIRQG (MSI)
75 *
76 * Trackpad DVT PIRQA (16)
77 * Trackpad DVT PIRQE (20)
78 */
79
80 /* Device interrupt pin register (board specific) */
81 RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
82 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP);
83 RCBA32(D30IP) = (NOINT << D30IP_PIP);
84 RCBA32(D29IP) = (INTA << D29IP_E1P);
85 RCBA32(D28IP) = (NOINT << D28IP_P1IP) | (INTA << D28IP_P2IP) |
86 (INTC << D28IP_P3IP) | (NOINT << D28IP_P4IP) |
87 (NOINT << D28IP_P5IP) | (NOINT << D28IP_P6IP) |
88 (NOINT << D28IP_P7IP) | (NOINT << D28IP_P8IP);
89 RCBA32(D27IP) = (INTA << D27IP_ZIP);
90 RCBA32(D26IP) = (INTA << D26IP_E2P);
91 RCBA32(D25IP) = (NOINT << D25IP_LIP);
92 RCBA32(D22IP) = (NOINT << D22IP_MEI1IP);
93
94 /* Device interrupt route registers */
95 DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC);
96 DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG);
97 DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE);
98 DIR_ROUTE(D27IR, PIRQA, PIRQH, PIRQA, PIRQB);
99 DIR_ROUTE(D26IR, PIRQF, PIRQE, PIRQG, PIRQH);
100 DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD);
101 DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD);
102
103 /* Enable IOAPIC (generic) */
104 RCBA16(OIC) = 0x0100;
105 /* PCH BWG says to read back the IOAPIC enable register */
106 (void) RCBA16(OIC);
107
108 /* Disable unused devices (board specific) */
109 reg32 = RCBA32(FD);
110 reg32 |= PCH_DISABLE_ALWAYS;
111 /* Disable PCI bridge so MRC does not probe this bus */
112 reg32 |= PCH_DISABLE_P2P;
113 RCBA32(FD) = reg32;
114}
115
116void main(unsigned long bist)
117{
118 int boot_mode = 0;
119 int cbmem_was_initted;
120 u32 pm1_cnt;
121 u16 pm1_sts;
122
Stefan Reinauera7198b32012-12-11 16:00:47 -0800123 struct pei_data pei_data = {
Edward O'Callaghanf5037bd2014-05-23 08:36:01 +1000124 .pei_version = PEI_VERSION,
125 .mchbar = DEFAULT_MCHBAR,
126 .dmibar = DEFAULT_DMIBAR,
127 .epbar = DEFAULT_EPBAR,
128 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
129 .smbusbar = SMBUS_IO_BASE,
130 .wdbbar = 0x4000000,
131 .wdbsize = 0x1000,
132 .hpet_address = CONFIG_HPET_ADDRESS,
133 .rcba = DEFAULT_RCBABASE,
134 .pmbase = DEFAULT_PMBASE,
135 .gpiobase = DEFAULT_GPIOBASE,
136 .thermalbase = 0xfed08000,
137 .system_type = 0, // 0 Mobile, 1 Desktop/Server
138 .tseg_size = CONFIG_SMM_TSEG_SIZE,
139 .spd_addresses = { 0xA0, 0x00,0xA4,0x00 },
140 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
141 .ec_present = 1,
Stefan Reinauera7198b32012-12-11 16:00:47 -0800142 // 0 = leave channel enabled
143 // 1 = disable dimm 0 on channel
144 // 2 = disable dimm 1 on channel
145 // 3 = disable dimm 0+1 on channel
Edward O'Callaghanf5037bd2014-05-23 08:36:01 +1000146 .dimm_channel0_disabled = 2,
147 .dimm_channel1_disabled = 2,
148 .max_ddr3_freq = 1600,
149 .usb_port_config = {
Stefan Reinauera7198b32012-12-11 16:00:47 -0800150 /* Empty and onboard Ports 0-7, set to un-used pin OC3 */
151 { 0, 3, 0x0000 }, /* P0: Empty */
152 { 1, 0, 0x0040 }, /* P1: Left USB 1 (OC0) */
153 { 1, 1, 0x0040 }, /* P2: Left USB 2 (OC1) */
154 { 1, 1, 0x0040 }, /* P3: Left USB 3 (OC1) */
155 { 0, 3, 0x0000 }, /* P4: Empty */
156 { 0, 3, 0x0000 }, /* P5: Empty */
157 { 0, 3, 0x0000 }, /* P6: Empty */
158 { 0, 3, 0x0000 }, /* P7: Empty */
159 /* Empty and onboard Ports 8-13, set to un-used pin OC4 */
160 { 1, 4, 0x0040 }, /* P8: MiniPCIe (WLAN) (no OC) */
161 { 0, 4, 0x0000 }, /* P9: Empty */
162 { 1, 4, 0x0040 }, /* P10: Camera (no OC) */
163 { 0, 4, 0x0000 }, /* P11: Empty */
164 { 0, 4, 0x0000 }, /* P12: Empty */
165 { 0, 4, 0x0000 }, /* P13: Empty */
166 },
167 };
168
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300169 timestamp_init(get_initial_timestamp());
170 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauera7198b32012-12-11 16:00:47 -0800171
172 if (bist == 0)
173 enable_lapic();
174
175 pch_enable_lpc();
176
177 /* Enable GPIOs */
178 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
179 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
180 setup_pch_gpios(&parrot_gpio_map);
181
182 /* Initialize console device(s) */
183 console_init();
184
185 /* Halt if there was a built in self test failure */
186 report_bist_failure(bist);
187
188 if (MCHBAR16(SSKPD) == 0xCAFE) {
189 printk(BIOS_DEBUG, "soft reset detected\n");
190 boot_mode = 1;
191
192 /* System is not happy after keyboard reset... */
193 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
194 outb(0x6, 0xcf9);
195 hlt();
196 }
197
198 /* Perform some early chipset initialization required
199 * before RAM initialization can work
200 */
201 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
202 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
203
204 /* Check PM1_STS[15] to see if we are waking from Sx */
205 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
206
207 /* Read PM1_CNT[12:10] to determine which Sx state */
208 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
209
210 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +0300211 if (acpi_s3_resume_allowed()) {
212 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
213 boot_mode = 2;
214 /* Clear SLP_TYPE. This will break stage2 but
215 * we care for that when we get there.
216 */
217 outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT);
218 } else {
219 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
220 }
Stefan Reinauera7198b32012-12-11 16:00:47 -0800221 }
222
223 post_code(0x38);
224 /* Enable SPD ROMs and DDR-III DRAM */
225 enable_smbus();
226
227 /* Prepare USB controller early in S3 resume */
228 if (boot_mode == 2)
229 enable_usb_bar();
230
231 post_code(0x39);
232
233 post_code(0x3a);
234 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300235 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauera7198b32012-12-11 16:00:47 -0800236 sdram_initialize(&pei_data);
237
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300238 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauera7198b32012-12-11 16:00:47 -0800239 post_code(0x3c);
240
241 rcba_config();
242 post_code(0x3d);
243
244 quick_ram_check();
245 post_code(0x3e);
246
247 MCHBAR16(SSKPD) = 0xCAFE;
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200248 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200249 if (boot_mode!=2)
250 save_mrc_data(&pei_data);
Stefan Reinauera7198b32012-12-11 16:00:47 -0800251
252#if CONFIG_HAVE_ACPI_RESUME
253 /* If there is no high memory area, we didn't boot before, so
254 * this is not a resume. In that case we just create the cbmem toc.
255 */
256
257 *(u32 *)CBMEM_BOOT_MODE = 0;
258 *(u32 *)CBMEM_RESUME_BACKUP = 0;
259
260 if ((boot_mode == 2) && cbmem_was_initted) {
261 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
262 if (resume_backup_memory) {
263 *(u32 *)CBMEM_BOOT_MODE = boot_mode;
264 *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory;
265 }
266 /* Magic for S3 resume */
267 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d);
268 } else if (boot_mode == 2) {
269 /* Failed S3 resume, reset to come up cleanly */
270 outb(0x6, 0xcf9);
271 hlt();
272 } else {
273 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
274 }
275#endif
276 post_code(0x3f);
277#if CONFIG_CHROMEOS
278 init_chromeos(boot_mode);
279#endif
Stefan Reinauera7198b32012-12-11 16:00:47 -0800280 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauera7198b32012-12-11 16:00:47 -0800281}