Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -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 Google Inc. |
| 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. |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <string.h> |
| 19 | #include <lib.h> |
| 20 | #include <timestamp.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 21 | #include <arch/io.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 22 | #include <device/pci.h> |
| 23 | #include <device/pci_def.h> |
| 24 | #include <device/pnp_def.h> |
| 25 | #include <cpu/x86/lapic.h> |
| 26 | #include <pc80/mc146818rtc.h> |
Kyösti Mälkki | 6722f8d | 2014-06-16 09:14:49 +0300 | [diff] [blame] | 27 | #include <arch/acpi.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 28 | #include <cbmem.h> |
| 29 | #include <console/console.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 30 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 31 | #include <northbridge/intel/sandybridge/raminit.h> |
| 32 | #include <southbridge/intel/bd82x6x/pch.h> |
| 33 | #include <southbridge/intel/bd82x6x/gpio.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 34 | #include "ec/google/chromeec/ec.h" |
| 35 | #include <arch/cpu.h> |
| 36 | #include <cpu/x86/bist.h> |
| 37 | #include <cpu/x86/msr.h> |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 38 | #include <halt.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 39 | #include "gpio.h" |
Vladimir Serbinenko | 0e90dae | 2015-05-18 10:29:06 +0200 | [diff] [blame] | 40 | #include <tpm.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 41 | #include <cbfs.h> |
| 42 | |
| 43 | #include <southbridge/intel/bd82x6x/chip.h> |
| 44 | |
| 45 | static void pch_enable_lpc(void) |
| 46 | { |
| 47 | const struct device *lpc; |
| 48 | const struct southbridge_intel_bd82x6x_config *config = NULL; |
| 49 | |
| 50 | lpc = dev_find_slot(0, PCI_DEVFN(0x1f, 0)); |
| 51 | if (!lpc) |
| 52 | return; |
| 53 | if (lpc->chip_info) |
| 54 | config = lpc->chip_info; |
| 55 | if (!config) |
| 56 | return; |
| 57 | |
| 58 | /* Set COM1/COM2 decode range */ |
| 59 | pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010); |
| 60 | |
| 61 | /* Enable PS/2 Keyboard/Mouse, EC areas and COM1 */ |
| 62 | pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN | \ |
| 63 | GAMEL_LPC_EN | COMA_LPC_EN); |
| 64 | |
| 65 | pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, config->gen1_dec); |
| 66 | pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, config->gen2_dec); |
| 67 | pci_write_config32(PCH_LPC_DEV, LPC_GEN3_DEC, config->gen3_dec); |
| 68 | pci_write_config32(PCH_LPC_DEV, LPC_GEN4_DEC, config->gen4_dec); |
| 69 | } |
| 70 | |
| 71 | static void rcba_config(void) |
| 72 | { |
| 73 | u32 reg32; |
| 74 | |
Kyösti Mälkki | 6f49906 | 2015-06-06 11:52:24 +0300 | [diff] [blame] | 75 | /* |
| 76 | * GFX INTA -> PIRQA (MSI) |
| 77 | * D28IP_P3IP WLAN INTA -> PIRQB |
| 78 | * D29IP_E1P EHCI1 INTA -> PIRQD |
| 79 | * D26IP_E2P EHCI2 INTA -> PIRQF |
| 80 | * D31IP_SIP SATA INTA -> PIRQF (MSI) |
| 81 | * D31IP_SMIP SMBUS INTB -> PIRQH |
| 82 | * D31IP_TTIP THRT INTC -> PIRQA |
| 83 | * D27IP_ZIP HDA INTA -> PIRQA (MSI) |
| 84 | * |
| 85 | * TRACKPAD -> PIRQE (Edge Triggered) |
| 86 | * TOUCHSCREEN -> PIRQG (Edge Triggered) |
| 87 | */ |
| 88 | |
| 89 | /* Device interrupt pin register (board specific) */ |
| 90 | RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) | |
| 91 | (INTB << D31IP_SMIP) | (INTA << D31IP_SIP); |
| 92 | RCBA32(D30IP) = (NOINT << D30IP_PIP); |
| 93 | RCBA32(D29IP) = (INTA << D29IP_E1P); |
| 94 | RCBA32(D28IP) = (INTA << D28IP_P3IP); |
| 95 | RCBA32(D27IP) = (INTA << D27IP_ZIP); |
| 96 | RCBA32(D26IP) = (INTA << D26IP_E2P); |
| 97 | RCBA32(D25IP) = (NOINT << D25IP_LIP); |
| 98 | RCBA32(D22IP) = (NOINT << D22IP_MEI1IP); |
| 99 | |
| 100 | /* Device interrupt route registers */ |
| 101 | DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC); |
| 102 | DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG); |
| 103 | DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE); |
| 104 | DIR_ROUTE(D27IR, PIRQA, PIRQH, PIRQA, PIRQB); |
| 105 | DIR_ROUTE(D26IR, PIRQF, PIRQE, PIRQG, PIRQH); |
| 106 | DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 107 | DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 108 | |
| 109 | /* Enable IOAPIC (generic) */ |
| 110 | RCBA16(OIC) = 0x0100; |
| 111 | /* PCH BWG says to read back the IOAPIC enable register */ |
| 112 | (void) RCBA16(OIC); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 113 | |
| 114 | /* Disable unused devices (board specific) */ |
| 115 | reg32 = RCBA32(FD); |
| 116 | reg32 |= PCH_DISABLE_ALWAYS; |
| 117 | RCBA32(FD) = reg32; |
| 118 | } |
| 119 | |
| 120 | static void copy_spd(struct pei_data *peid) |
| 121 | { |
| 122 | const int gpio_vector[] = {41, 42, 43, 10, -1}; |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 123 | char *spd_file; |
| 124 | size_t spd_file_len; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 125 | int spd_index = get_gpios(gpio_vector); |
| 126 | |
| 127 | printk(BIOS_DEBUG, "spd index %d\n", spd_index); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 128 | spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD, |
| 129 | &spd_file_len); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 130 | if (!spd_file) |
| 131 | die("SPD data not found."); |
| 132 | |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 133 | if (spd_file_len < ((spd_index + 1) * sizeof(peid->spd_data[0]))) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 134 | printk(BIOS_ERR, "spd index override to 0 - old hardware?\n"); |
| 135 | spd_index = 0; |
| 136 | } |
| 137 | |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 138 | if (spd_file_len < sizeof(peid->spd_data[0])) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 139 | die("Missing SPD data."); |
| 140 | |
| 141 | memcpy(peid->spd_data[0], |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 142 | spd_file + |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 143 | spd_index * sizeof(peid->spd_data[0]), |
| 144 | sizeof(peid->spd_data[0])); |
| 145 | } |
| 146 | |
Aaron Durbin | a0a3727 | 2014-08-14 08:35:11 -0500 | [diff] [blame] | 147 | #include <cpu/intel/romstage.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 148 | void main(unsigned long bist) |
| 149 | { |
| 150 | int boot_mode = 0; |
| 151 | int cbmem_was_initted; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 152 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 153 | struct pei_data pei_data = { |
Edward O'Callaghan | 6cec824 | 2014-05-24 04:16:57 +1000 | [diff] [blame] | 154 | .pei_version = PEI_VERSION, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 155 | .mchbar = (uintptr_t)DEFAULT_MCHBAR, |
| 156 | .dmibar = (uintptr_t)DEFAULT_DMIBAR, |
Edward O'Callaghan | 6cec824 | 2014-05-24 04:16:57 +1000 | [diff] [blame] | 157 | .epbar = DEFAULT_EPBAR, |
| 158 | .pciexbar = CONFIG_MMCONF_BASE_ADDRESS, |
| 159 | .smbusbar = SMBUS_IO_BASE, |
| 160 | .wdbbar = 0x4000000, |
| 161 | .wdbsize = 0x1000, |
| 162 | .hpet_address = CONFIG_HPET_ADDRESS, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 163 | .rcba = (uintptr_t)DEFAULT_RCBABASE, |
Edward O'Callaghan | 6cec824 | 2014-05-24 04:16:57 +1000 | [diff] [blame] | 164 | .pmbase = DEFAULT_PMBASE, |
| 165 | .gpiobase = DEFAULT_GPIOBASE, |
| 166 | .thermalbase = 0xfed08000, |
| 167 | .system_type = 0, // 0 Mobile, 1 Desktop/Server |
| 168 | .tseg_size = CONFIG_SMM_TSEG_SIZE, |
| 169 | .ts_addresses = { 0x00, 0x00, 0x00, 0x00 }, |
| 170 | .ec_present = 1, |
| 171 | .ddr3lv_support = 1, |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 172 | // 0 = leave channel enabled |
| 173 | // 1 = disable dimm 0 on channel |
| 174 | // 2 = disable dimm 1 on channel |
| 175 | // 3 = disable dimm 0+1 on channel |
Edward O'Callaghan | 6cec824 | 2014-05-24 04:16:57 +1000 | [diff] [blame] | 176 | .dimm_channel0_disabled = 2, |
| 177 | .dimm_channel1_disabled = 2, |
| 178 | .max_ddr3_freq = 1600, |
| 179 | .usb_port_config = { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 180 | /* Empty and onboard Ports 0-7, set to un-used pin OC3 */ |
| 181 | { 0, 3, 0x0000 }, /* P0: Empty */ |
| 182 | { 1, 0, 0x0040 }, /* P1: Left USB 1 (OC0) */ |
| 183 | { 1, 1, 0x0040 }, /* P2: Left USB 2 (OC1) */ |
| 184 | { 1, 3, 0x0040 }, /* P3: SDCARD (no OC) */ |
| 185 | { 0, 3, 0x0000 }, /* P4: Empty */ |
| 186 | { 1, 3, 0x0040 }, /* P5: WWAN (no OC) */ |
| 187 | { 0, 3, 0x0000 }, /* P6: Empty */ |
| 188 | { 0, 3, 0x0000 }, /* P7: Empty */ |
| 189 | /* Empty and onboard Ports 8-13, set to un-used pin OC4 */ |
| 190 | { 1, 4, 0x0040 }, /* P8: Camera (no OC) */ |
| 191 | { 1, 4, 0x0040 }, /* P9: Bluetooth (no OC) */ |
| 192 | { 0, 4, 0x0000 }, /* P10: Empty */ |
| 193 | { 0, 4, 0x0000 }, /* P11: Empty */ |
| 194 | { 0, 4, 0x0000 }, /* P12: Empty */ |
| 195 | { 0, 4, 0x0000 }, /* P13: Empty */ |
| 196 | }, |
| 197 | }; |
| 198 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 199 | timestamp_init(get_initial_timestamp()); |
| 200 | timestamp_add_now(TS_START_ROMSTAGE); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 201 | |
| 202 | if (bist == 0) |
| 203 | enable_lapic(); |
| 204 | |
| 205 | pch_enable_lpc(); |
| 206 | |
| 207 | /* Enable GPIOs */ |
| 208 | pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1); |
| 209 | pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10); |
| 210 | setup_pch_gpios(&link_gpio_map); |
| 211 | |
| 212 | /* Initialize console device(s) */ |
| 213 | console_init(); |
| 214 | |
| 215 | /* Halt if there was a built in self test failure */ |
| 216 | report_bist_failure(bist); |
| 217 | |
| 218 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 219 | printk(BIOS_DEBUG, "soft reset detected\n"); |
| 220 | boot_mode = 1; |
| 221 | |
| 222 | /* System is not happy after keyboard reset... */ |
| 223 | printk(BIOS_DEBUG, "Issuing CF9 warm reset\n"); |
| 224 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 225 | halt(); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* Perform some early chipset initialization required |
| 229 | * before RAM initialization can work |
| 230 | */ |
| 231 | sandybridge_early_initialization(SANDYBRIDGE_MOBILE); |
| 232 | printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n"); |
| 233 | |
Vladimir Serbinenko | 332f14b | 2014-09-05 16:29:41 +0200 | [diff] [blame] | 234 | boot_mode = southbridge_detect_s3_resume() ? 2 : 0; |
| 235 | if (boot_mode == 0) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 236 | /* This is the fastest way to let users know |
| 237 | * the Intel CPU is now alive. |
| 238 | */ |
| 239 | google_chromeec_kbbacklight(100); |
| 240 | } |
| 241 | |
| 242 | post_code(0x38); |
| 243 | /* Enable SPD ROMs and DDR-III DRAM */ |
| 244 | enable_smbus(); |
| 245 | |
| 246 | /* Prepare USB controller early in S3 resume */ |
| 247 | if (boot_mode == 2) |
| 248 | enable_usb_bar(); |
| 249 | |
| 250 | post_code(0x39); |
| 251 | |
| 252 | copy_spd(&pei_data); |
| 253 | |
| 254 | post_code(0x3a); |
| 255 | pei_data.boot_mode = boot_mode; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 256 | timestamp_add_now(TS_BEFORE_INITRAM); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 257 | sdram_initialize(&pei_data); |
| 258 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 259 | timestamp_add_now(TS_AFTER_INITRAM); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 260 | post_code(0x3c); |
| 261 | |
| 262 | rcba_config(); |
| 263 | post_code(0x3d); |
| 264 | |
| 265 | quick_ram_check(); |
| 266 | post_code(0x3e); |
| 267 | |
Kyösti Mälkki | 2d8520b | 2014-01-06 17:20:31 +0200 | [diff] [blame] | 268 | cbmem_was_initted = !cbmem_recovery(boot_mode==2); |
Kyösti Mälkki | 7893848 | 2014-01-04 11:02:45 +0200 | [diff] [blame] | 269 | if (boot_mode!=2) |
| 270 | save_mrc_data(&pei_data); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 271 | |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 272 | if (boot_mode==2 && !cbmem_was_initted) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 273 | /* Failed S3 resume, reset to come up cleanly */ |
| 274 | outb(0x6, 0xcf9); |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 275 | halt(); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 276 | } |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 277 | northbridge_romstage_finalize(boot_mode==2); |
| 278 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 279 | post_code(0x3f); |
Vladimir Serbinenko | 0e90dae | 2015-05-18 10:29:06 +0200 | [diff] [blame] | 280 | if (CONFIG_LPC_TPM) { |
| 281 | init_tpm(boot_mode == 2); |
| 282 | } |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 283 | } |