Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [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 |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <string.h> |
| 23 | #include <lib.h> |
| 24 | #include <timestamp.h> |
| 25 | #include <arch/io.h> |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 26 | #include <device/pci_def.h> |
| 27 | #include <device/pnp_def.h> |
| 28 | #include <cpu/x86/lapic.h> |
| 29 | #include <pc80/mc146818rtc.h> |
Kyösti Mälkki | 6722f8d | 2014-06-16 09:14:49 +0300 | [diff] [blame] | 30 | #include <arch/acpi.h> |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 31 | #include <cbmem.h> |
| 32 | #include <console/console.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 33 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 34 | #include <northbridge/intel/sandybridge/raminit.h> |
| 35 | #include <southbridge/intel/bd82x6x/pch.h> |
| 36 | #include <southbridge/intel/bd82x6x/gpio.h> |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 37 | #include <arch/cpu.h> |
| 38 | #include <cpu/x86/bist.h> |
| 39 | #include <cpu/x86/msr.h> |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 40 | #include <halt.h> |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 41 | #include "gpio.h" |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 42 | #include <cbfs.h> |
Vladimir Serbinenko | 0e90dae | 2015-05-18 10:29:06 +0200 | [diff] [blame^] | 43 | #include <tpm.h> |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 44 | #include "ec/compal/ene932/ec.h" |
| 45 | |
| 46 | static void pch_enable_lpc(void) |
| 47 | { |
| 48 | /* Parrot EC Decode Range Port60/64, Port62/66 */ |
| 49 | /* Enable EC, PS/2 Keyboard/Mouse */ |
| 50 | pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN); |
| 51 | |
| 52 | /* Map EC_IO decode to the LPC bus */ |
| 53 | pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, (EC_IO & ~3) | 0x00040001); |
| 54 | |
| 55 | /* Map EC registers 68/6C decode to the LPC bus */ |
| 56 | pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, (68 & ~3) | 0x00040001); |
| 57 | } |
| 58 | |
| 59 | static void rcba_config(void) |
| 60 | { |
| 61 | u32 reg32; |
| 62 | |
Vladimir Serbinenko | 33b535f | 2014-10-19 10:13:14 +0200 | [diff] [blame] | 63 | southbridge_configure_default_intmap(); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 64 | |
| 65 | /* Disable unused devices (board specific) */ |
| 66 | reg32 = RCBA32(FD); |
| 67 | reg32 |= PCH_DISABLE_ALWAYS; |
| 68 | /* Disable PCI bridge so MRC does not probe this bus */ |
| 69 | reg32 |= PCH_DISABLE_P2P; |
| 70 | RCBA32(FD) = reg32; |
| 71 | } |
| 72 | |
Aaron Durbin | a0a3727 | 2014-08-14 08:35:11 -0500 | [diff] [blame] | 73 | #include <cpu/intel/romstage.h> |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 74 | void main(unsigned long bist) |
| 75 | { |
| 76 | int boot_mode = 0; |
| 77 | int cbmem_was_initted; |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 78 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 79 | struct pei_data pei_data = { |
Edward O'Callaghan | f5037bd | 2014-05-23 08:36:01 +1000 | [diff] [blame] | 80 | .pei_version = PEI_VERSION, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 81 | .mchbar = (uintptr_t)DEFAULT_MCHBAR, |
| 82 | .dmibar = (uintptr_t)DEFAULT_DMIBAR, |
Edward O'Callaghan | f5037bd | 2014-05-23 08:36:01 +1000 | [diff] [blame] | 83 | .epbar = DEFAULT_EPBAR, |
| 84 | .pciexbar = CONFIG_MMCONF_BASE_ADDRESS, |
| 85 | .smbusbar = SMBUS_IO_BASE, |
| 86 | .wdbbar = 0x4000000, |
| 87 | .wdbsize = 0x1000, |
| 88 | .hpet_address = CONFIG_HPET_ADDRESS, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 89 | .rcba = (uintptr_t)DEFAULT_RCBABASE, |
Edward O'Callaghan | f5037bd | 2014-05-23 08:36:01 +1000 | [diff] [blame] | 90 | .pmbase = DEFAULT_PMBASE, |
| 91 | .gpiobase = DEFAULT_GPIOBASE, |
| 92 | .thermalbase = 0xfed08000, |
| 93 | .system_type = 0, // 0 Mobile, 1 Desktop/Server |
| 94 | .tseg_size = CONFIG_SMM_TSEG_SIZE, |
| 95 | .spd_addresses = { 0xA0, 0x00,0xA4,0x00 }, |
| 96 | .ts_addresses = { 0x00, 0x00, 0x00, 0x00 }, |
| 97 | .ec_present = 1, |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 98 | // 0 = leave channel enabled |
| 99 | // 1 = disable dimm 0 on channel |
| 100 | // 2 = disable dimm 1 on channel |
| 101 | // 3 = disable dimm 0+1 on channel |
Edward O'Callaghan | f5037bd | 2014-05-23 08:36:01 +1000 | [diff] [blame] | 102 | .dimm_channel0_disabled = 2, |
| 103 | .dimm_channel1_disabled = 2, |
| 104 | .max_ddr3_freq = 1600, |
| 105 | .usb_port_config = { |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 106 | /* Empty and onboard Ports 0-7, set to un-used pin OC3 */ |
| 107 | { 0, 3, 0x0000 }, /* P0: Empty */ |
| 108 | { 1, 0, 0x0040 }, /* P1: Left USB 1 (OC0) */ |
| 109 | { 1, 1, 0x0040 }, /* P2: Left USB 2 (OC1) */ |
| 110 | { 1, 1, 0x0040 }, /* P3: Left USB 3 (OC1) */ |
| 111 | { 0, 3, 0x0000 }, /* P4: Empty */ |
| 112 | { 0, 3, 0x0000 }, /* P5: Empty */ |
| 113 | { 0, 3, 0x0000 }, /* P6: Empty */ |
| 114 | { 0, 3, 0x0000 }, /* P7: Empty */ |
| 115 | /* Empty and onboard Ports 8-13, set to un-used pin OC4 */ |
| 116 | { 1, 4, 0x0040 }, /* P8: MiniPCIe (WLAN) (no OC) */ |
| 117 | { 0, 4, 0x0000 }, /* P9: Empty */ |
| 118 | { 1, 4, 0x0040 }, /* P10: Camera (no OC) */ |
| 119 | { 0, 4, 0x0000 }, /* P11: Empty */ |
| 120 | { 0, 4, 0x0000 }, /* P12: Empty */ |
| 121 | { 0, 4, 0x0000 }, /* P13: Empty */ |
| 122 | }, |
| 123 | }; |
| 124 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 125 | timestamp_init(get_initial_timestamp()); |
| 126 | timestamp_add_now(TS_START_ROMSTAGE); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 127 | |
| 128 | if (bist == 0) |
| 129 | enable_lapic(); |
| 130 | |
| 131 | pch_enable_lpc(); |
| 132 | |
| 133 | /* Enable GPIOs */ |
| 134 | pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1); |
| 135 | pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10); |
| 136 | setup_pch_gpios(&parrot_gpio_map); |
| 137 | |
| 138 | /* Initialize console device(s) */ |
| 139 | console_init(); |
| 140 | |
| 141 | /* Halt if there was a built in self test failure */ |
| 142 | report_bist_failure(bist); |
| 143 | |
| 144 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 145 | printk(BIOS_DEBUG, "soft reset detected\n"); |
| 146 | boot_mode = 1; |
| 147 | |
| 148 | /* System is not happy after keyboard reset... */ |
| 149 | printk(BIOS_DEBUG, "Issuing CF9 warm reset\n"); |
| 150 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 151 | halt(); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* Perform some early chipset initialization required |
| 155 | * before RAM initialization can work |
| 156 | */ |
| 157 | sandybridge_early_initialization(SANDYBRIDGE_MOBILE); |
| 158 | printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n"); |
| 159 | |
Vladimir Serbinenko | 332f14b | 2014-09-05 16:29:41 +0200 | [diff] [blame] | 160 | boot_mode = southbridge_detect_s3_resume() ? 2 : 0; |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 161 | |
| 162 | post_code(0x38); |
| 163 | /* Enable SPD ROMs and DDR-III DRAM */ |
| 164 | enable_smbus(); |
| 165 | |
| 166 | /* Prepare USB controller early in S3 resume */ |
| 167 | if (boot_mode == 2) |
| 168 | enable_usb_bar(); |
| 169 | |
| 170 | post_code(0x39); |
| 171 | |
| 172 | post_code(0x3a); |
| 173 | pei_data.boot_mode = boot_mode; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 174 | timestamp_add_now(TS_BEFORE_INITRAM); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 175 | sdram_initialize(&pei_data); |
| 176 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 177 | timestamp_add_now(TS_AFTER_INITRAM); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 178 | post_code(0x3c); |
| 179 | |
| 180 | rcba_config(); |
| 181 | post_code(0x3d); |
| 182 | |
| 183 | quick_ram_check(); |
| 184 | post_code(0x3e); |
| 185 | |
Kyösti Mälkki | 2d8520b | 2014-01-06 17:20:31 +0200 | [diff] [blame] | 186 | cbmem_was_initted = !cbmem_recovery(boot_mode==2); |
Kyösti Mälkki | 7893848 | 2014-01-04 11:02:45 +0200 | [diff] [blame] | 187 | if (boot_mode!=2) |
| 188 | save_mrc_data(&pei_data); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 189 | |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 190 | if (boot_mode==2 && !cbmem_was_initted) { |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 191 | /* Failed S3 resume, reset to come up cleanly */ |
| 192 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 193 | halt(); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 194 | } |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 195 | northbridge_romstage_finalize(boot_mode==2); |
| 196 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 197 | post_code(0x3f); |
Vladimir Serbinenko | 0e90dae | 2015-05-18 10:29:06 +0200 | [diff] [blame^] | 198 | if (CONFIG_LPC_TPM) { |
| 199 | init_tpm(boot_mode == 2); |
| 200 | } |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 201 | timestamp_add_now(TS_END_ROMSTAGE); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 202 | } |