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. |
| 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 | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 27 | #include <device/pci.h> |
| 28 | #include <device/pci_def.h> |
| 29 | #include <device/pnp_def.h> |
| 30 | #include <cpu/x86/lapic.h> |
| 31 | #include <pc80/mc146818rtc.h> |
| 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 "ec/google/chromeec/ec.h" |
| 39 | #include <arch/cpu.h> |
| 40 | #include <cpu/x86/bist.h> |
| 41 | #include <cpu/x86/msr.h> |
| 42 | #include "gpio.h" |
| 43 | #if CONFIG_CHROMEOS |
| 44 | #include <vendorcode/google/chromeos/chromeos.h> |
| 45 | #endif |
| 46 | #include <cbfs.h> |
| 47 | |
| 48 | #include <southbridge/intel/bd82x6x/chip.h> |
| 49 | |
| 50 | static void pch_enable_lpc(void) |
| 51 | { |
| 52 | const struct device *lpc; |
| 53 | const struct southbridge_intel_bd82x6x_config *config = NULL; |
| 54 | |
| 55 | lpc = dev_find_slot(0, PCI_DEVFN(0x1f, 0)); |
| 56 | if (!lpc) |
| 57 | return; |
| 58 | if (lpc->chip_info) |
| 59 | config = lpc->chip_info; |
| 60 | if (!config) |
| 61 | return; |
| 62 | |
| 63 | /* Set COM1/COM2 decode range */ |
| 64 | pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010); |
| 65 | |
| 66 | /* Enable PS/2 Keyboard/Mouse, EC areas and COM1 */ |
| 67 | pci_write_config16(PCH_LPC_DEV, LPC_EN, KBC_LPC_EN | MC_LPC_EN | \ |
| 68 | GAMEL_LPC_EN | COMA_LPC_EN); |
| 69 | |
| 70 | pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, config->gen1_dec); |
| 71 | pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, config->gen2_dec); |
| 72 | pci_write_config32(PCH_LPC_DEV, LPC_GEN3_DEC, config->gen3_dec); |
| 73 | pci_write_config32(PCH_LPC_DEV, LPC_GEN4_DEC, config->gen4_dec); |
| 74 | } |
| 75 | |
| 76 | static void rcba_config(void) |
| 77 | { |
| 78 | u32 reg32; |
| 79 | |
| 80 | /* |
| 81 | * GFX INTA -> PIRQA (MSI) |
| 82 | * D28IP_P3IP WLAN INTA -> PIRQB |
| 83 | * D29IP_E1P EHCI1 INTA -> PIRQD |
| 84 | * D26IP_E2P EHCI2 INTA -> PIRQF |
| 85 | * D31IP_SIP SATA INTA -> PIRQF (MSI) |
| 86 | * D31IP_SMIP SMBUS INTB -> PIRQH |
| 87 | * D31IP_TTIP THRT INTC -> PIRQA |
| 88 | * D27IP_ZIP HDA INTA -> PIRQA (MSI) |
| 89 | * |
| 90 | * TRACKPAD -> PIRQE (Edge Triggered) |
| 91 | * TOUCHSCREEN -> PIRQG (Edge Triggered) |
| 92 | */ |
| 93 | |
| 94 | /* Device interrupt pin register (board specific) */ |
| 95 | RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) | |
| 96 | (INTB << D31IP_SMIP) | (INTA << D31IP_SIP); |
| 97 | RCBA32(D30IP) = (NOINT << D30IP_PIP); |
| 98 | RCBA32(D29IP) = (INTA << D29IP_E1P); |
| 99 | RCBA32(D28IP) = (INTA << D28IP_P3IP); |
| 100 | RCBA32(D27IP) = (INTA << D27IP_ZIP); |
| 101 | RCBA32(D26IP) = (INTA << D26IP_E2P); |
| 102 | RCBA32(D25IP) = (NOINT << D25IP_LIP); |
| 103 | RCBA32(D22IP) = (NOINT << D22IP_MEI1IP); |
| 104 | |
| 105 | /* Device interrupt route registers */ |
| 106 | DIR_ROUTE(D31IR, PIRQB, PIRQH, PIRQA, PIRQC); |
| 107 | DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG); |
| 108 | DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE); |
| 109 | DIR_ROUTE(D27IR, PIRQA, PIRQH, PIRQA, PIRQB); |
| 110 | DIR_ROUTE(D26IR, PIRQF, PIRQE, PIRQG, PIRQH); |
| 111 | DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 112 | DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 113 | |
| 114 | /* Enable IOAPIC (generic) */ |
| 115 | RCBA16(OIC) = 0x0100; |
| 116 | /* PCH BWG says to read back the IOAPIC enable register */ |
| 117 | (void) RCBA16(OIC); |
| 118 | |
| 119 | /* Disable unused devices (board specific) */ |
| 120 | reg32 = RCBA32(FD); |
| 121 | reg32 |= PCH_DISABLE_ALWAYS; |
| 122 | RCBA32(FD) = reg32; |
| 123 | } |
| 124 | |
| 125 | static void copy_spd(struct pei_data *peid) |
| 126 | { |
| 127 | const int gpio_vector[] = {41, 42, 43, 10, -1}; |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 128 | char *spd_file; |
| 129 | size_t spd_file_len; |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 130 | int spd_index = get_gpios(gpio_vector); |
| 131 | |
| 132 | printk(BIOS_DEBUG, "spd index %d\n", spd_index); |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 133 | spd_file = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "spd.bin", 0xab, |
| 134 | &spd_file_len); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 135 | if (!spd_file) |
| 136 | die("SPD data not found."); |
| 137 | |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 138 | if (spd_file_len < ((spd_index + 1) * sizeof(peid->spd_data[0]))) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 139 | printk(BIOS_ERR, "spd index override to 0 - old hardware?\n"); |
| 140 | spd_index = 0; |
| 141 | } |
| 142 | |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 143 | if (spd_file_len < sizeof(peid->spd_data[0])) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 144 | die("Missing SPD data."); |
| 145 | |
| 146 | memcpy(peid->spd_data[0], |
Vladimir Serbinenko | 1287416 | 2014-01-12 14:12:15 +0100 | [diff] [blame] | 147 | spd_file + |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 148 | spd_index * sizeof(peid->spd_data[0]), |
| 149 | sizeof(peid->spd_data[0])); |
| 150 | } |
| 151 | |
| 152 | void main(unsigned long bist) |
| 153 | { |
| 154 | int boot_mode = 0; |
| 155 | int cbmem_was_initted; |
| 156 | u32 pm1_cnt; |
| 157 | u16 pm1_sts; |
| 158 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 159 | struct pei_data pei_data = { |
| 160 | pei_version: PEI_VERSION, |
| 161 | mchbar: DEFAULT_MCHBAR, |
| 162 | dmibar: DEFAULT_DMIBAR, |
| 163 | epbar: DEFAULT_EPBAR, |
| 164 | pciexbar: CONFIG_MMCONF_BASE_ADDRESS, |
| 165 | smbusbar: SMBUS_IO_BASE, |
| 166 | wdbbar: 0x4000000, |
| 167 | wdbsize: 0x1000, |
| 168 | hpet_address: CONFIG_HPET_ADDRESS, |
| 169 | rcba: DEFAULT_RCBABASE, |
| 170 | pmbase: DEFAULT_PMBASE, |
| 171 | gpiobase: DEFAULT_GPIOBASE, |
| 172 | thermalbase: 0xfed08000, |
| 173 | system_type: 0, // 0 Mobile, 1 Desktop/Server |
| 174 | tseg_size: CONFIG_SMM_TSEG_SIZE, |
| 175 | ts_addresses: { 0x00, 0x00, 0x00, 0x00 }, |
| 176 | ec_present: 1, |
| 177 | ddr3lv_support: 1, |
| 178 | // 0 = leave channel enabled |
| 179 | // 1 = disable dimm 0 on channel |
| 180 | // 2 = disable dimm 1 on channel |
| 181 | // 3 = disable dimm 0+1 on channel |
| 182 | dimm_channel0_disabled: 2, |
| 183 | dimm_channel1_disabled: 2, |
| 184 | max_ddr3_freq: 1600, |
| 185 | usb_port_config: { |
| 186 | /* Empty and onboard Ports 0-7, set to un-used pin OC3 */ |
| 187 | { 0, 3, 0x0000 }, /* P0: Empty */ |
| 188 | { 1, 0, 0x0040 }, /* P1: Left USB 1 (OC0) */ |
| 189 | { 1, 1, 0x0040 }, /* P2: Left USB 2 (OC1) */ |
| 190 | { 1, 3, 0x0040 }, /* P3: SDCARD (no OC) */ |
| 191 | { 0, 3, 0x0000 }, /* P4: Empty */ |
| 192 | { 1, 3, 0x0040 }, /* P5: WWAN (no OC) */ |
| 193 | { 0, 3, 0x0000 }, /* P6: Empty */ |
| 194 | { 0, 3, 0x0000 }, /* P7: Empty */ |
| 195 | /* Empty and onboard Ports 8-13, set to un-used pin OC4 */ |
| 196 | { 1, 4, 0x0040 }, /* P8: Camera (no OC) */ |
| 197 | { 1, 4, 0x0040 }, /* P9: Bluetooth (no OC) */ |
| 198 | { 0, 4, 0x0000 }, /* P10: Empty */ |
| 199 | { 0, 4, 0x0000 }, /* P11: Empty */ |
| 200 | { 0, 4, 0x0000 }, /* P12: Empty */ |
| 201 | { 0, 4, 0x0000 }, /* P13: Empty */ |
| 202 | }, |
| 203 | }; |
| 204 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 205 | timestamp_init(get_initial_timestamp()); |
| 206 | timestamp_add_now(TS_START_ROMSTAGE); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 207 | |
| 208 | if (bist == 0) |
| 209 | enable_lapic(); |
| 210 | |
| 211 | pch_enable_lpc(); |
| 212 | |
| 213 | /* Enable GPIOs */ |
| 214 | pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1); |
| 215 | pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10); |
| 216 | setup_pch_gpios(&link_gpio_map); |
| 217 | |
| 218 | /* Initialize console device(s) */ |
| 219 | console_init(); |
| 220 | |
| 221 | /* Halt if there was a built in self test failure */ |
| 222 | report_bist_failure(bist); |
| 223 | |
| 224 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 225 | printk(BIOS_DEBUG, "soft reset detected\n"); |
| 226 | boot_mode = 1; |
| 227 | |
| 228 | /* System is not happy after keyboard reset... */ |
| 229 | printk(BIOS_DEBUG, "Issuing CF9 warm reset\n"); |
| 230 | outb(0x6, 0xcf9); |
| 231 | hlt(); |
| 232 | } |
| 233 | |
| 234 | /* Perform some early chipset initialization required |
| 235 | * before RAM initialization can work |
| 236 | */ |
| 237 | sandybridge_early_initialization(SANDYBRIDGE_MOBILE); |
| 238 | printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n"); |
| 239 | |
| 240 | /* Check PM1_STS[15] to see if we are waking from Sx */ |
| 241 | pm1_sts = inw(DEFAULT_PMBASE + PM1_STS); |
| 242 | |
| 243 | /* Read PM1_CNT[12:10] to determine which Sx state */ |
| 244 | pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT); |
| 245 | |
| 246 | if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) { |
| 247 | #if CONFIG_HAVE_ACPI_RESUME |
| 248 | printk(BIOS_DEBUG, "Resume from S3 detected.\n"); |
| 249 | boot_mode = 2; |
| 250 | /* Clear SLP_TYPE. This will break stage2 but |
| 251 | * we care for that when we get there. |
| 252 | */ |
| 253 | outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT); |
| 254 | #else |
| 255 | printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n"); |
| 256 | #endif |
| 257 | } else { |
| 258 | /* This is the fastest way to let users know |
| 259 | * the Intel CPU is now alive. |
| 260 | */ |
| 261 | google_chromeec_kbbacklight(100); |
| 262 | } |
| 263 | |
| 264 | post_code(0x38); |
| 265 | /* Enable SPD ROMs and DDR-III DRAM */ |
| 266 | enable_smbus(); |
| 267 | |
| 268 | /* Prepare USB controller early in S3 resume */ |
| 269 | if (boot_mode == 2) |
| 270 | enable_usb_bar(); |
| 271 | |
| 272 | post_code(0x39); |
| 273 | |
| 274 | copy_spd(&pei_data); |
| 275 | |
| 276 | post_code(0x3a); |
| 277 | pei_data.boot_mode = boot_mode; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 278 | timestamp_add_now(TS_BEFORE_INITRAM); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 279 | sdram_initialize(&pei_data); |
| 280 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 281 | timestamp_add_now(TS_AFTER_INITRAM); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 282 | post_code(0x3c); |
| 283 | |
| 284 | rcba_config(); |
| 285 | post_code(0x3d); |
| 286 | |
| 287 | quick_ram_check(); |
| 288 | post_code(0x3e); |
| 289 | |
| 290 | MCHBAR16(SSKPD) = 0xCAFE; |
Kyösti Mälkki | 2d8520b | 2014-01-06 17:20:31 +0200 | [diff] [blame] | 291 | cbmem_was_initted = !cbmem_recovery(boot_mode==2); |
Kyösti Mälkki | 7893848 | 2014-01-04 11:02:45 +0200 | [diff] [blame] | 292 | if (boot_mode!=2) |
| 293 | save_mrc_data(&pei_data); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 294 | |
| 295 | #if CONFIG_HAVE_ACPI_RESUME |
| 296 | /* If there is no high memory area, we didn't boot before, so |
| 297 | * this is not a resume. In that case we just create the cbmem toc. |
| 298 | */ |
| 299 | |
| 300 | *(u32 *)CBMEM_BOOT_MODE = 0; |
| 301 | *(u32 *)CBMEM_RESUME_BACKUP = 0; |
| 302 | |
| 303 | if ((boot_mode == 2) && cbmem_was_initted) { |
| 304 | void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME); |
| 305 | if (resume_backup_memory) { |
| 306 | *(u32 *)CBMEM_BOOT_MODE = boot_mode; |
| 307 | *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory; |
| 308 | } |
| 309 | /* Magic for S3 resume */ |
| 310 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d); |
| 311 | } else if (boot_mode == 2) { |
| 312 | /* Failed S3 resume, reset to come up cleanly */ |
| 313 | outb(0x6, 0xcf9); |
| 314 | hlt(); |
| 315 | } else { |
| 316 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe); |
| 317 | } |
| 318 | #endif |
| 319 | post_code(0x3f); |
| 320 | #if CONFIG_CHROMEOS |
| 321 | init_chromeos(boot_mode); |
| 322 | #endif |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 323 | timestamp_add_now(TS_END_ROMSTAGE); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 324 | } |