Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 1 | /* |
| 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/byteorder.h> |
| 26 | #include <arch/io.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 27 | #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älkki | 6722f8d | 2014-06-16 09:14:49 +0300 | [diff] [blame] | 31 | #include <arch/acpi.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 32 | #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" |
Kyösti Mälkki | 926a8d1 | 2014-04-27 22:17:22 +0300 | [diff] [blame] | 42 | #include <bootmode.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 43 | #if CONFIG_CHROMEOS |
| 44 | #include <vendorcode/google/chromeos/chromeos.h> |
| 45 | #endif |
| 46 | #include <cbfs.h> |
| 47 | #include <ec/quanta/it8518/ec.h> |
| 48 | #include "ec.h" |
| 49 | #include "onboard.h" |
| 50 | |
| 51 | static void pch_enable_lpc(void) |
| 52 | { |
| 53 | /* |
| 54 | * Enable: |
| 55 | * EC Decode Range Port62/66 |
| 56 | * SuperIO Port2E/2F |
| 57 | * PS/2 Keyboard/Mouse Port60/64 |
| 58 | * FDD Port3F0h-3F5h and Port3F7h |
| 59 | */ |
| 60 | pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN | |
| 61 | CNF1_LPC_EN | FDD_LPC_EN); |
| 62 | |
| 63 | /* Stout EC Decode Range Port68/6C */ |
| 64 | pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, (0x68 | 0x40001)); |
| 65 | } |
| 66 | |
| 67 | static void rcba_config(void) |
| 68 | { |
| 69 | u32 reg32; |
| 70 | |
| 71 | /* |
| 72 | * GFX INTA -> PIRQA (MSI) |
| 73 | * D20IP_XHCI XHCI INTA -> PIRQD (MSI) |
| 74 | * D26IP_E2P EHCI #2 INTA -> PIRQF |
| 75 | * D27IP_ZIP HDA INTA -> PIRQA (MSI) |
| 76 | * D28IP_P2IP WLAN INTA -> PIRQD |
| 77 | * D28IP_P3IP Card Reader INTB -> PIRQE |
| 78 | * D28IP_P6IP LAN INTC -> PIRQB |
| 79 | * D29IP_E1P EHCI #1 INTA -> PIRQD |
| 80 | * D31IP_SIP SATA INTA -> PIRQB (MSI) |
| 81 | * D31IP_SMIP SMBUS INTB -> PIRQH |
| 82 | */ |
| 83 | |
| 84 | /* Device interrupt pin register (board specific) */ |
| 85 | RCBA32(D31IP) = (NOINT << D31IP_TTIP) | (NOINT << D31IP_SIP2) | |
| 86 | (INTB << D31IP_SMIP) | (INTA << D31IP_SIP); |
| 87 | RCBA32(D30IP) = (NOINT << D30IP_PIP); |
| 88 | RCBA32(D29IP) = (INTA << D29IP_E1P); |
| 89 | RCBA32(D28IP) = (NOINT << D28IP_P1IP) | (INTA << D28IP_P2IP) | |
| 90 | (INTB << D28IP_P3IP) | (NOINT << D28IP_P4IP) | |
| 91 | (NOINT << D28IP_P5IP) | (INTC << D28IP_P6IP) | |
| 92 | (NOINT << D28IP_P7IP) | (NOINT << D28IP_P8IP); |
| 93 | RCBA32(D27IP) = (INTA << D27IP_ZIP); |
| 94 | RCBA32(D26IP) = (INTA << D26IP_E2P); |
| 95 | RCBA32(D25IP) = (NOINT << D25IP_LIP); |
| 96 | RCBA32(D22IP) = (NOINT << D22IP_MEI1IP); |
| 97 | RCBA32(D20IP) = (INTA << D20IP_XHCIIP); |
| 98 | |
| 99 | /* Device interrupt route registers */ |
| 100 | DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC); |
| 101 | DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG); |
| 102 | DIR_ROUTE(D28IR, PIRQD, PIRQE, PIRQB, PIRQC); |
| 103 | DIR_ROUTE(D27IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 104 | DIR_ROUTE(D26IR, PIRQF, PIRQB, PIRQC, PIRQD); |
| 105 | DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 106 | DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 107 | DIR_ROUTE(D20IR, PIRQD, PIRQE, PIRQF, PIRQG); |
| 108 | |
| 109 | /* Enable IOAPIC (generic) */ |
| 110 | RCBA16(OIC) = 0x0100; |
| 111 | /* PCH BWG says to read back the IOAPIC enable register */ |
| 112 | (void) RCBA16(OIC); |
| 113 | |
| 114 | /* Disable unused devices (board specific) */ |
| 115 | reg32 = RCBA32(FD); |
| 116 | reg32 |= PCH_DISABLE_ALWAYS; |
| 117 | /* Disable PCI bridge so MRC does not probe this bus */ |
| 118 | reg32 |= PCH_DISABLE_P2P; |
| 119 | RCBA32(FD) = reg32; |
| 120 | } |
| 121 | |
| 122 | // FIXME, this function is generic code that should go to sb/... or |
| 123 | // nb/../early_init.c |
| 124 | static void early_pch_init(void) |
| 125 | { |
| 126 | // Nothing to do for stout |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * The Stout EC needs to be reset to RW mode. It is important that |
| 131 | * the RTC_PWR_STS is not set until ramstage EC init. |
| 132 | */ |
| 133 | static void early_ec_init(void) |
| 134 | { |
| 135 | u8 ec_status = ec_read(EC_STATUS_REG); |
Kyösti Mälkki | 926a8d1 | 2014-04-27 22:17:22 +0300 | [diff] [blame] | 136 | int rec_mode = IS_ENABLED(CONFIG_BOOTMODE_STRAPS) && |
| 137 | get_recovery_mode_switch(); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 138 | |
| 139 | if (((ec_status & 0x3) == EC_IN_RO_MODE) || |
| 140 | ((ec_status & 0x3) == EC_IN_RECOVERY_MODE)) { |
| 141 | |
| 142 | printk(BIOS_DEBUG, "EC Cold Boot Detected\n"); |
| 143 | if (!rec_mode) { |
| 144 | /* |
| 145 | * Tell EC to exit RO mode |
| 146 | */ |
| 147 | printk(BIOS_DEBUG, "EC will exit RO mode and boot normally\n"); |
| 148 | ec_write_cmd(EC_CMD_EXIT_BOOT_BLOCK); |
| 149 | die("wait for ec to reset"); |
| 150 | } |
| 151 | } else { |
| 152 | printk(BIOS_DEBUG, "EC Warm Boot Detected\n"); |
| 153 | ec_write_cmd(EC_CMD_WARM_RESET); |
| 154 | } |
| 155 | } |
| 156 | |
Aaron Durbin | a0a3727 | 2014-08-14 08:35:11 -0500 | [diff] [blame] | 157 | #include <cpu/intel/romstage.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 158 | void main(unsigned long bist) |
| 159 | { |
| 160 | int boot_mode = 0; |
| 161 | int cbmem_was_initted; |
| 162 | u32 pm1_cnt; |
| 163 | u16 pm1_sts; |
| 164 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 165 | struct pei_data pei_data = { |
| 166 | pei_version: PEI_VERSION, |
| 167 | mchbar: DEFAULT_MCHBAR, |
| 168 | dmibar: DEFAULT_DMIBAR, |
| 169 | epbar: DEFAULT_EPBAR, |
| 170 | pciexbar: CONFIG_MMCONF_BASE_ADDRESS, |
| 171 | smbusbar: SMBUS_IO_BASE, |
| 172 | wdbbar: 0x4000000, |
| 173 | wdbsize: 0x1000, |
| 174 | hpet_address: CONFIG_HPET_ADDRESS, |
| 175 | rcba: DEFAULT_RCBABASE, |
| 176 | pmbase: DEFAULT_PMBASE, |
| 177 | gpiobase: DEFAULT_GPIOBASE, |
| 178 | thermalbase: 0xfed08000, |
| 179 | system_type: 0, // 0 Mobile, 1 Desktop/Server |
| 180 | tseg_size: CONFIG_SMM_TSEG_SIZE, |
| 181 | spd_addresses: { 0xA0, 0x00,0xA4,0x00 }, |
| 182 | ts_addresses: { 0x00, 0x00, 0x00, 0x00 }, |
| 183 | ec_present: 1, |
| 184 | // 0 = leave channel enabled |
| 185 | // 1 = disable dimm 0 on channel |
| 186 | // 2 = disable dimm 1 on channel |
| 187 | // 3 = disable dimm 0+1 on channel |
| 188 | dimm_channel0_disabled: 2, |
| 189 | dimm_channel1_disabled: 2, |
| 190 | max_ddr3_freq: 1600, |
| 191 | usb_port_config: { |
| 192 | /* enabled usb oc pin length */ |
| 193 | { 1, 0, 0x0040 }, /* P0: USB 3.0 1 (OC0) */ |
| 194 | { 1, 0, 0x0040 }, /* P1: USB 3.0 2 (OC0) */ |
| 195 | { 0, 1, 0x0000 }, /* P2: Empty */ |
| 196 | { 1, 1, 0x0040 }, /* P3: Camera (no OC) */ |
| 197 | { 1, 1, 0x0040 }, /* P4: WLAN (no OC) */ |
| 198 | { 1, 1, 0x0040 }, /* P5: WWAN (no OC) */ |
| 199 | { 0, 1, 0x0000 }, /* P6: Empty */ |
| 200 | { 0, 1, 0x0000 }, /* P7: Empty */ |
| 201 | { 0, 5, 0x0000 }, /* P8: Empty */ |
| 202 | { 1, 4, 0x0040 }, /* P9: USB 2.0 (AUO4) (OC4) */ |
| 203 | { 0, 5, 0x0000 }, /* P10: Empty */ |
| 204 | { 0, 5, 0x0000 }, /* P11: Empty */ |
| 205 | { 0, 5, 0x0000 }, /* P12: Empty */ |
| 206 | { 1, 5, 0x0040 }, /* P13: Bluetooth (no OC) */ |
| 207 | }, |
| 208 | usb3: { |
| 209 | mode: XHCI_MODE, |
| 210 | hs_port_switch_mask: XHCI_PORTS, |
| 211 | preboot_support: XHCI_PREBOOT, |
| 212 | xhci_streams: XHCI_STREAMS, |
| 213 | }, |
| 214 | }; |
| 215 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 216 | timestamp_init(get_initial_timestamp()); |
| 217 | timestamp_add_now(TS_START_ROMSTAGE); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 218 | |
| 219 | if (bist == 0) |
| 220 | enable_lapic(); |
| 221 | |
| 222 | pch_enable_lpc(); |
| 223 | |
| 224 | /* Enable GPIOs */ |
| 225 | pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1); |
| 226 | pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10); |
| 227 | setup_pch_gpios(&stout_gpio_map); |
| 228 | |
| 229 | /* Initialize console device(s) */ |
| 230 | console_init(); |
| 231 | |
| 232 | /* Halt if there was a built in self test failure */ |
| 233 | report_bist_failure(bist); |
| 234 | |
| 235 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 236 | printk(BIOS_DEBUG, "soft reset detected\n"); |
| 237 | boot_mode = 1; |
| 238 | |
| 239 | /* System is not happy after keyboard reset... */ |
| 240 | printk(BIOS_DEBUG, "Issuing CF9 warm reset\n"); |
| 241 | outb(0x6, 0xcf9); |
| 242 | hlt(); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | /* Perform some early chipset initialization required |
| 247 | * before RAM initialization can work |
| 248 | */ |
| 249 | sandybridge_early_initialization(SANDYBRIDGE_MOBILE); |
| 250 | printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n"); |
| 251 | |
| 252 | /* Check PM1_STS[15] to see if we are waking from Sx */ |
| 253 | pm1_sts = inw(DEFAULT_PMBASE + PM1_STS); |
| 254 | |
| 255 | /* Read PM1_CNT[12:10] to determine which Sx state */ |
| 256 | pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT); |
| 257 | |
| 258 | if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) { |
Kyösti Mälkki | 6722f8d | 2014-06-16 09:14:49 +0300 | [diff] [blame] | 259 | if (acpi_s3_resume_allowed()) { |
| 260 | printk(BIOS_DEBUG, "Resume from S3 detected.\n"); |
| 261 | boot_mode = 2; |
| 262 | /* Clear SLP_TYPE. This will break stage2 but |
| 263 | * we care for that when we get there. |
| 264 | */ |
| 265 | outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT); |
| 266 | } else { |
| 267 | printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n"); |
| 268 | } |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /* Do ec reset as early as possible, but skip it on S3 resume */ |
| 272 | if (boot_mode < 2) |
| 273 | early_ec_init(); |
| 274 | |
| 275 | post_code(0x38); |
| 276 | /* Enable SPD ROMs and DDR-III DRAM */ |
| 277 | enable_smbus(); |
| 278 | |
| 279 | /* Prepare USB controller early in S3 resume */ |
| 280 | if (boot_mode == 2) |
| 281 | enable_usb_bar(); |
| 282 | |
| 283 | post_code(0x39); |
| 284 | |
| 285 | post_code(0x3a); |
| 286 | pei_data.boot_mode = boot_mode; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 287 | timestamp_add_now(TS_BEFORE_INITRAM); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 288 | sdram_initialize(&pei_data); |
| 289 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 290 | timestamp_add_now(TS_AFTER_INITRAM); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 291 | post_code(0x3b); |
| 292 | /* Perform some initialization that must run before stage2 */ |
| 293 | early_pch_init(); |
| 294 | post_code(0x3c); |
| 295 | |
| 296 | rcba_config(); |
| 297 | post_code(0x3d); |
| 298 | |
| 299 | quick_ram_check(); |
| 300 | post_code(0x3e); |
| 301 | |
Kyösti Mälkki | 2d8520b | 2014-01-06 17:20:31 +0200 | [diff] [blame] | 302 | cbmem_was_initted = !cbmem_recovery(boot_mode==2); |
Kyösti Mälkki | 7893848 | 2014-01-04 11:02:45 +0200 | [diff] [blame] | 303 | if (boot_mode!=2) |
| 304 | save_mrc_data(&pei_data); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 305 | |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame^] | 306 | if (boot_mode==2 && !cbmem_was_initted) { |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 307 | /* Failed S3 resume, reset to come up cleanly */ |
| 308 | outb(0x6, 0xcf9); |
| 309 | hlt(); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 310 | } |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame^] | 311 | northbridge_romstage_finalize(boot_mode==2); |
| 312 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 313 | post_code(0x3f); |
| 314 | #if CONFIG_CHROMEOS |
| 315 | init_chromeos(boot_mode); |
| 316 | #endif |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 317 | timestamp_add_now(TS_END_ROMSTAGE); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 318 | } |