blob: ce064bbe8b1c5da606910c8f7d6a350bc5d91c3d [file] [log] [blame]
Stefan Reinauer155e9b52012-04-27 23:19:58 +02001/*
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
Patrick Georgib890a122015-03-26 15:17:45 +010018 * Foundation, Inc.
Stefan Reinauer155e9b52012-04-27 23:19:58 +020019 */
20
21#include <stdint.h>
22#include <string.h>
23#include <lib.h>
24#include <timestamp.h>
25#include <arch/io.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020026#include <device/pci_def.h>
27#include <device/pnp_def.h>
28#include <cpu/x86/lapic.h>
29#include <pc80/mc146818rtc.h>
30#include <cbfs.h>
Kyösti Mälkki6722f8d2014-06-16 09:14:49 +030031#include <arch/acpi.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020032#include <cbmem.h>
33#include <console/console.h>
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +030034#include <bootmode.h>
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +020035#include <tpm.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110036#include <northbridge/intel/sandybridge/sandybridge.h>
37#include <northbridge/intel/sandybridge/raminit.h>
38#include <southbridge/intel/bd82x6x/pch.h>
39#include <southbridge/intel/bd82x6x/gpio.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020040#include <arch/cpu.h>
41#include <cpu/x86/bist.h>
42#include <cpu/x86/msr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010043#include <halt.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020044#include "option_table.h"
45#include "gpio.h"
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020046#if CONFIG_DRIVERS_UART_8250IO
Edward O'Callaghan74834e02015-01-04 04:17:35 +110047#include <superio/smsc/lpc47n207/lpc47n207.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020048#endif
Stefan Reinauer155e9b52012-04-27 23:19:58 +020049
50static void pch_enable_lpc(void)
51{
52 /* Set COM1/COM2 decode range */
53 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
54
Kyösti Mälkkiafa7b132014-02-13 17:16:22 +020055#if CONFIG_DRIVERS_UART_8250IO
Stefan Reinauer155e9b52012-04-27 23:19:58 +020056 /* Enable SuperIO + EC + KBC + COM1 + lpc47n207 config*/
57 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | MC_LPC_EN |
58 KBC_LPC_EN | CNF2_LPC_EN | COMA_LPC_EN);
59
60 /* map full 256 bytes at 0x1600 to the LPC bus */
61 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601);
62
63 try_enabling_LPC47N207_uart();
64#else
65 /* Enable SuperIO + EC + KBC */
66 pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | MC_LPC_EN |
67 KBC_LPC_EN);
68#endif
69}
70
71static void rcba_config(void)
72{
73 u32 reg32;
74
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020075 southbridge_configure_default_intmap();
Stefan Reinauer155e9b52012-04-27 23:19:58 +020076
77 /* Enable IOAPIC (generic) */
78 RCBA16(OIC) = 0x0100;
79 /* PCH BWG says to read back the IOAPIC enable register */
80 (void) RCBA16(OIC);
81
Stefan Reinauer155e9b52012-04-27 23:19:58 +020082 /* Disable unused devices (board specific) */
83 reg32 = RCBA32(FD);
84 reg32 |= PCH_DISABLE_ALWAYS;
85 RCBA32(FD) = reg32;
86}
87
88static void early_pch_init(void)
89{
90 u8 reg8;
91
92 // reset rtc power status
93 reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4);
94 reg8 &= ~(1 << 2);
95 pci_write_config8(PCH_LPC_DEV, 0xa4, reg8);
96}
97
Aaron Durbina0a37272014-08-14 08:35:11 -050098#include <cpu/intel/romstage.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020099void main(unsigned long bist)
100{
101 int boot_mode = 0;
102 int cbmem_was_initted;
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200103
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200104 struct pei_data pei_data = {
Edward O'Callaghanc9714bc2014-10-29 06:16:51 +1100105 .pei_version = PEI_VERSION,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800106 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
107 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
Edward O'Callaghanc9714bc2014-10-29 06:16:51 +1100108 .epbar = DEFAULT_EPBAR,
109 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
110 .smbusbar = SMBUS_IO_BASE,
111 .wdbbar = 0x4000000,
112 .wdbsize = 0x1000,
113 .hpet_address = CONFIG_HPET_ADDRESS,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800114 .rcba = (uintptr_t)DEFAULT_RCBABASE,
Edward O'Callaghanc9714bc2014-10-29 06:16:51 +1100115 .pmbase = DEFAULT_PMBASE,
116 .gpiobase = DEFAULT_GPIOBASE,
117 .thermalbase = 0xfed08000,
118 .system_type = 0, // 0 Mobile, 1 Desktop/Server
119 .tseg_size = CONFIG_SMM_TSEG_SIZE,
120 .spd_addresses = { 0xa0, 0x00,0x00,0x00 },
121 .ts_addresses = { 0x30, 0x00, 0x00, 0x00 },
122 .ec_present = 1,
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200123 // 0 = leave channel enabled
124 // 1 = disable dimm 0 on channel
125 // 2 = disable dimm 1 on channel
126 // 3 = disable dimm 0+1 on channel
Edward O'Callaghanc9714bc2014-10-29 06:16:51 +1100127 .dimm_channel0_disabled = 2,
128 .dimm_channel1_disabled = 2,
129 .max_ddr3_freq = 1333,
130 .usb_port_config = {
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200131 { 1, 0, 0x0080 }, /* P0: Port 0 (OC0) */
132 { 1, 1, 0x0080 }, /* P1: Port 1 (OC1) */
133 { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */
134 { 1, 0, 0x0040 }, /* P3: MMC (no OC) */
135 { 0, 0, 0x0000 }, /* P4: Empty */
136 { 0, 0, 0x0000 }, /* P5: Empty */
137 { 0, 0, 0x0000 }, /* P6: Empty */
138 { 0, 0, 0x0000 }, /* P7: Empty */
139 { 1, 4, 0x0040 }, /* P8: MINIPCIE2 (no OC) */
140 { 0, 4, 0x0000 }, /* P9: Empty */
141 { 0, 4, 0x0000 }, /* P10: Empty */
142 { 1, 4, 0x0040 }, /* P11: Camera (no OC) */
143 { 0, 4, 0x0000 }, /* P12: Empty */
144 { 0, 4, 0x0000 }, /* P13: Empty */
145 },
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200146 };
147
148 typedef const uint8_t spd_blob[256];
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200149 spd_blob *spd_data;
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100150 size_t spd_file_len;
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200151
152
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300153 timestamp_init(get_initial_timestamp());
154 timestamp_add_now(TS_START_ROMSTAGE);
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200155
156 if (bist == 0)
157 enable_lapic();
158
159 pch_enable_lpc();
160
161 /* Enable GPIOs */
162 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1);
163 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
164 setup_pch_gpios(&lumpy_gpio_map);
165
166 console_init();
167
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +0300168 init_bootmode_straps();
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200169
170 /* Halt if there was a built in self test failure */
171 report_bist_failure(bist);
172
173 if (MCHBAR16(SSKPD) == 0xCAFE) {
174 printk(BIOS_DEBUG, "soft reset detected\n");
175 boot_mode = 1;
176
177 /* System is not happy after keyboard reset... */
178 printk(BIOS_DEBUG, "Issuing CF9 warm reset\n");
179 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100180 halt();
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200181 }
182
183 /* Perform some early chipset initialization required
184 * before RAM initialization can work
185 */
186 sandybridge_early_initialization(SANDYBRIDGE_MOBILE);
187 printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n");
188
Vladimir Serbinenko332f14b2014-09-05 16:29:41 +0200189 boot_mode = southbridge_detect_s3_resume() ? 2 : 0;
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200190
191 post_code(0x38);
192 /* Enable SPD ROMs and DDR-III DRAM */
193 enable_smbus();
194
195 /* Prepare USB controller early in S3 resume */
196 if (boot_mode == 2)
197 enable_usb_bar();
198
199 u32 gp_lvl2 = inl(DEFAULT_GPIOBASE + 0x38);
200 u8 gpio33, gpio41, gpio49;
201 gpio33 = (gp_lvl2 >> (33-32)) & 1;
202 gpio41 = (gp_lvl2 >> (41-32)) & 1;
203 gpio49 = (gp_lvl2 >> (49-32)) & 1;
204 printk(BIOS_DEBUG, "Memory Straps:\n");
205 printk(BIOS_DEBUG, " - memory capacity %dGB\n",
206 gpio33 ? 2 : 1);
207 printk(BIOS_DEBUG, " - die revision %d\n",
208 gpio41 ? 2 : 1);
209 printk(BIOS_DEBUG, " - vendor %s\n",
210 gpio49 ? "Samsung" : "Other");
211
212 int spd_index = 0;
213
214 switch ((gpio49 << 2) | (gpio41 << 1) | gpio33) {
215 case 0: // Other 1G Rev 1
216 spd_index = 0;
217 break;
218 case 2: // Other 1G Rev 2
219 spd_index = 1;
220 break;
221 case 1: // Other 2G Rev 1
222 case 3: // Other 2G Rev 2
223 spd_index = 2;
224 break;
225 case 4: // Samsung 1G Rev 1
226 spd_index = 3;
227 break;
228 case 6: // Samsung 1G Rev 2
229 spd_index = 4;
230 break;
231 case 5: // Samsung 2G Rev 1
232 case 7: // Samsung 2G Rev 2
233 spd_index = 5;
234 break;
235 }
236
Aaron Durbina30f7e62015-03-31 20:33:53 -0500237 spd_data = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "spd.bin",
238 CBFS_TYPE_SPD, &spd_file_len);
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100239 if (!spd_data)
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200240 die("SPD data not found.");
Vladimir Serbinenko12874162014-01-12 14:12:15 +0100241 if (spd_file_len < (spd_index + 1) * 256)
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200242 die("Missing SPD data.");
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200243 // leave onboard dimm address at f0, and copy spd data there.
244 memcpy(pei_data.spd_data[0], spd_data[spd_index], 256);
245
246 post_code(0x39);
247 pei_data.boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300248 timestamp_add_now(TS_BEFORE_INITRAM);
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200249 sdram_initialize(&pei_data);
250
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300251 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200252 post_code(0x3a);
253 /* Perform some initialization that must run before stage2 */
254 early_pch_init();
255 post_code(0x3b);
256
257 rcba_config();
258 post_code(0x3c);
259
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200260 quick_ram_check();
Stefan Reinauerafcaac22012-06-18 15:43:50 -0700261 post_code(0x3e);
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200262
Kyösti Mälkki2d8520b2014-01-06 17:20:31 +0200263 cbmem_was_initted = !cbmem_recovery(boot_mode==2);
Kyösti Mälkki78938482014-01-04 11:02:45 +0200264 if (boot_mode!=2)
265 save_mrc_data(&pei_data);
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200266
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200267 if (boot_mode == 2 && !cbmem_was_initted) {
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200268 /* Failed S3 resume, reset to come up cleanly */
269 outb(0x6, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100270 halt();
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200271 }
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200272 northbridge_romstage_finalize(boot_mode==2);
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200273 post_code(0x3f);
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +0200274 if (CONFIG_LPC_TPM) {
275 init_tpm(boot_mode == 2);
276 }
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200277 timestamp_add_now(TS_END_ROMSTAGE);
Stefan Reinauer155e9b52012-04-27 23:19:58 +0200278}