Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [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/io.h> |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [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> |
| 30 | #include <cbmem.h> |
| 31 | #include <console/console.h> |
| 32 | #include "superio/smsc/sio1007/early_serial.c" |
| 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" |
| 37 | #include <arch/cpu.h> |
| 38 | #include <cpu/x86/bist.h> |
| 39 | #include <cpu/x86/msr.h> |
| 40 | #include "gpio.h" |
| 41 | #if CONFIG_CHROMEOS |
| 42 | #include <vendorcode/google/chromeos/chromeos.h> |
| 43 | #endif |
| 44 | |
Marc Jones | c4b6f3b | 2013-11-05 17:47:37 -0700 | [diff] [blame^] | 45 | #define SIO_PORT 0x164e |
| 46 | |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 47 | static void pch_enable_lpc(void) |
| 48 | { |
| 49 | device_t dev = PCH_LPC_DEV; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 50 | |
| 51 | /* Set COM1/COM2 decode range */ |
| 52 | pci_write_config16(dev, LPC_IO_DEC, 0x0010); |
| 53 | |
Marc Jones | c4b6f3b | 2013-11-05 17:47:37 -0700 | [diff] [blame^] | 54 | /* Enable SuperIO + PS/2 Keyboard/Mouse */ |
| 55 | u16 lpc_config = CNF1_LPC_EN | CNF2_LPC_EN | KBC_LPC_EN; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 56 | pci_write_config16(dev, LPC_EN, lpc_config); |
| 57 | |
| 58 | /* Map 256 bytes at 0x1600 to the LPC bus. */ |
| 59 | pci_write_config32(dev, LPC_GEN1_DEC, 0xfc1601); |
| 60 | |
Marc Jones | c4b6f3b | 2013-11-05 17:47:37 -0700 | [diff] [blame^] | 61 | /* Map a range for the runtime_port registers to the LPC bus. */ |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 62 | pci_write_config32(dev, LPC_GEN2_DEC, 0xc0181); |
| 63 | |
Marc Jones | c4b6f3b | 2013-11-05 17:47:37 -0700 | [diff] [blame^] | 64 | /* Enable COM1 */ |
| 65 | if (sio1007_enable_uart_at(SIO_PORT)) { |
| 66 | pci_write_config16(dev, LPC_EN, |
| 67 | lpc_config | COMA_LPC_EN); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | static void rcba_config(void) |
| 72 | { |
| 73 | u32 reg32; |
| 74 | |
| 75 | /* |
| 76 | * GFX INTA -> PIRQA (MSI) |
| 77 | * D28IP_P1IP WLAN INTA -> PIRQB |
| 78 | * D28IP_P4IP ETH0 INTB -> PIRQC |
| 79 | * D29IP_E1P EHCI1 INTA -> PIRQD |
| 80 | * D26IP_E2P EHCI2 INTA -> PIRQE |
| 81 | * D31IP_SIP SATA INTA -> PIRQF (MSI) |
| 82 | * D31IP_SMIP SMBUS INTB -> PIRQG |
| 83 | * D31IP_TTIP THRT INTC -> PIRQH |
| 84 | * D27IP_ZIP HDA INTA -> PIRQG (MSI) |
| 85 | */ |
| 86 | |
| 87 | /* Device interrupt pin register (board specific) */ |
| 88 | RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) | |
| 89 | (INTB << D31IP_SMIP) | (INTA << D31IP_SIP); |
| 90 | RCBA32(D30IP) = (NOINT << D30IP_PIP); |
| 91 | RCBA32(D29IP) = (INTA << D29IP_E1P); |
| 92 | RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) | |
| 93 | (INTB << D28IP_P4IP); |
| 94 | RCBA32(D27IP) = (INTA << D27IP_ZIP); |
| 95 | RCBA32(D26IP) = (INTA << D26IP_E2P); |
| 96 | RCBA32(D25IP) = (NOINT << D25IP_LIP); |
| 97 | RCBA32(D22IP) = (NOINT << D22IP_MEI1IP); |
| 98 | |
| 99 | /* Device interrupt route registers */ |
| 100 | DIR_ROUTE(D31IR, PIRQF, PIRQG, PIRQH, PIRQA); |
| 101 | DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG); |
| 102 | DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE); |
| 103 | DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB); |
| 104 | DIR_ROUTE(D26IR, PIRQE, PIRQF, PIRQG, PIRQH); |
| 105 | DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 106 | DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 107 | |
| 108 | /* Enable IOAPIC (generic) */ |
| 109 | RCBA16(OIC) = 0x0100; |
| 110 | /* PCH BWG says to read back the IOAPIC enable register */ |
| 111 | (void) RCBA16(OIC); |
| 112 | |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 113 | /* Disable unused devices (board specific) */ |
| 114 | reg32 = RCBA32(FD); |
| 115 | reg32 |= PCH_DISABLE_ALWAYS; |
| 116 | RCBA32(FD) = reg32; |
| 117 | } |
| 118 | |
| 119 | // FIXME, this function is generic code that should go to sb/... or |
| 120 | // nb/../early_init.c |
| 121 | static void early_pch_init(void) |
| 122 | { |
| 123 | u8 reg8; |
| 124 | |
| 125 | // reset rtc power status |
| 126 | reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4); |
| 127 | reg8 &= ~(1 << 2); |
| 128 | pci_write_config8(PCH_LPC_DEV, 0xa4, reg8); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void setup_sio_gpios(void) |
| 132 | { |
Marc Jones | c4b6f3b | 2013-11-05 17:47:37 -0700 | [diff] [blame^] | 133 | const u16 port = SIO_PORT; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 134 | const u16 runtime_port = 0x180; |
| 135 | |
| 136 | /* Turn on configuration mode. */ |
| 137 | outb(0x55, port); |
| 138 | |
| 139 | /* Set the GPIO direction, polarity, and type. */ |
| 140 | sio1007_setreg(port, 0x31, 1 << 0, 1 << 0); |
| 141 | sio1007_setreg(port, 0x32, 0 << 0, 1 << 0); |
| 142 | sio1007_setreg(port, 0x33, 0 << 0, 1 << 0); |
| 143 | |
| 144 | /* Set the base address for the runtime register block. */ |
| 145 | sio1007_setreg(port, 0x30, runtime_port >> 4, 0xff); |
| 146 | sio1007_setreg(port, 0x21, runtime_port >> 12, 0xff); |
| 147 | |
| 148 | /* Turn on address decoding for it. */ |
| 149 | sio1007_setreg(port, 0x3a, 1 << 1, 1 << 1); |
| 150 | |
| 151 | /* Set the value of GPIO 10 by changing GP1, bit 0. */ |
| 152 | u8 byte; |
| 153 | byte = inb(runtime_port + 0xc); |
| 154 | byte |= (1 << 0); |
| 155 | outb(byte, runtime_port + 0xc); |
| 156 | |
| 157 | /* Turn off address decoding for it. */ |
| 158 | sio1007_setreg(port, 0x3a, 0 << 1, 1 << 1); |
| 159 | |
| 160 | /* Turn off configuration mode. */ |
| 161 | outb(0xaa, port); |
| 162 | } |
| 163 | |
| 164 | void main(unsigned long bist) |
| 165 | { |
| 166 | int boot_mode = 0; |
| 167 | int cbmem_was_initted; |
| 168 | u32 pm1_cnt; |
| 169 | u16 pm1_sts; |
| 170 | |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 171 | struct pei_data pei_data = { |
| 172 | pei_version: PEI_VERSION, |
Stefan Reinauer | e6063fe | 2012-04-30 14:57:51 -0700 | [diff] [blame] | 173 | mchbar: DEFAULT_MCHBAR, |
| 174 | dmibar: DEFAULT_DMIBAR, |
| 175 | epbar: DEFAULT_EPBAR, |
| 176 | pciexbar: CONFIG_MMCONF_BASE_ADDRESS, |
| 177 | smbusbar: SMBUS_IO_BASE, |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 178 | wdbbar: 0x4000000, |
| 179 | wdbsize: 0x1000, |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 180 | hpet_address: CONFIG_HPET_ADDRESS, |
Stefan Reinauer | e6063fe | 2012-04-30 14:57:51 -0700 | [diff] [blame] | 181 | rcba: DEFAULT_RCBABASE, |
| 182 | pmbase: DEFAULT_PMBASE, |
| 183 | gpiobase: DEFAULT_GPIOBASE, |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 184 | thermalbase: 0xfed08000, |
| 185 | system_type: 0, // 0 Mobile, 1 Desktop/Server |
| 186 | tseg_size: CONFIG_SMM_TSEG_SIZE, |
| 187 | spd_addresses: { 0xa0, 0x00, 0xa4, 0x00 }, |
| 188 | ts_addresses: { 0x00, 0x00, 0x00, 0x00 }, |
| 189 | ec_present: 0, |
| 190 | // 0 = leave channel enabled |
| 191 | // 1 = disable dimm 0 on channel |
| 192 | // 2 = disable dimm 1 on channel |
| 193 | // 3 = disable dimm 0+1 on channel |
| 194 | dimm_channel0_disabled: 2, |
| 195 | dimm_channel1_disabled: 2, |
| 196 | max_ddr3_freq: 1600, |
| 197 | usb_port_config: { |
| 198 | { 1, 0, 0x0040 }, /* P0: Front port (OC0) */ |
| 199 | { 1, 1, 0x0040 }, /* P1: Back port (OC1) */ |
| 200 | { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */ |
| 201 | { 1, 0, 0x0040 }, /* P3: MMC (no OC) */ |
| 202 | { 1, 2, 0x0040 }, /* P4: Front port (OC2) */ |
| 203 | { 0, 0, 0x0000 }, /* P5: Empty */ |
| 204 | { 0, 0, 0x0000 }, /* P6: Empty */ |
| 205 | { 0, 0, 0x0000 }, /* P7: Empty */ |
| 206 | { 1, 4, 0x0040 }, /* P8: Back port (OC4) */ |
| 207 | { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */ |
| 208 | { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */ |
| 209 | { 0, 4, 0x0000 }, /* P11: Empty */ |
| 210 | { 1, 6, 0x0040 }, /* P12: Back port (OC6) */ |
| 211 | { 1, 5, 0x0040 }, /* P13: Back port (OC5) */ |
| 212 | }, |
| 213 | }; |
| 214 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 215 | timestamp_init(get_initial_timestamp()); |
| 216 | timestamp_add_now(TS_START_ROMSTAGE); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 217 | |
| 218 | if (bist == 0) |
| 219 | enable_lapic(); |
| 220 | |
| 221 | pch_enable_lpc(); |
| 222 | |
| 223 | /* Enable GPIOs */ |
| 224 | pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1); |
| 225 | pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10); |
Gabe Black | 599e204 | 2012-03-30 14:33:02 -0700 | [diff] [blame] | 226 | setup_pch_gpios(&emeraldlake2_gpio_map); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 227 | setup_sio_gpios(); |
| 228 | |
| 229 | /* Early SuperIO setup */ |
| 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 | /* Perform some early chipset initialization required |
| 246 | * before RAM initialization can work |
| 247 | */ |
| 248 | sandybridge_early_initialization(SANDYBRIDGE_MOBILE); |
| 249 | printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n"); |
| 250 | |
| 251 | /* Check PM1_STS[15] to see if we are waking from Sx */ |
| 252 | pm1_sts = inw(DEFAULT_PMBASE + PM1_STS); |
| 253 | |
| 254 | /* Read PM1_CNT[12:10] to determine which Sx state */ |
| 255 | pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT); |
| 256 | |
| 257 | if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) { |
| 258 | #if CONFIG_HAVE_ACPI_RESUME |
| 259 | printk(BIOS_DEBUG, "Resume from S3 detected.\n"); |
| 260 | boot_mode = 2; |
| 261 | /* Clear SLP_TYPE. This will break stage2 but |
| 262 | * we care for that when we get there. |
| 263 | */ |
| 264 | outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT); |
| 265 | #else |
| 266 | printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n"); |
| 267 | #endif |
| 268 | } |
| 269 | |
| 270 | post_code(0x38); |
| 271 | /* Enable SPD ROMs and DDR-III DRAM */ |
| 272 | enable_smbus(); |
| 273 | |
| 274 | /* Prepare USB controller early in S3 resume */ |
| 275 | if (boot_mode == 2) |
| 276 | enable_usb_bar(); |
| 277 | |
| 278 | post_code(0x3a); |
| 279 | pei_data.boot_mode = boot_mode; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 280 | timestamp_add_now(TS_BEFORE_INITRAM); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 281 | sdram_initialize(&pei_data); |
| 282 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 283 | timestamp_add_now(TS_AFTER_INITRAM); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 284 | post_code(0x3b); |
| 285 | /* Perform some initialization that must run before stage2 */ |
| 286 | early_pch_init(); |
| 287 | post_code(0x3c); |
| 288 | |
| 289 | /* This should probably go away. Until now it is required |
| 290 | * and mainboard specific |
| 291 | */ |
| 292 | rcba_config(); |
| 293 | post_code(0x3d); |
| 294 | |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 295 | quick_ram_check(); |
Stefan Reinauer | afcaac2 | 2012-06-18 15:43:50 -0700 | [diff] [blame] | 296 | post_code(0x3e); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 297 | |
| 298 | MCHBAR16(SSKPD) = 0xCAFE; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 299 | cbmem_was_initted = !cbmem_initialize(); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 300 | |
| 301 | #if CONFIG_HAVE_ACPI_RESUME |
| 302 | /* If there is no high memory area, we didn't boot before, so |
| 303 | * this is not a resume. In that case we just create the cbmem toc. |
| 304 | */ |
| 305 | |
| 306 | *(u32 *)CBMEM_BOOT_MODE = 0; |
| 307 | *(u32 *)CBMEM_RESUME_BACKUP = 0; |
| 308 | |
| 309 | if ((boot_mode == 2) && cbmem_was_initted) { |
| 310 | void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME); |
| 311 | if (resume_backup_memory) { |
| 312 | *(u32 *)CBMEM_BOOT_MODE = boot_mode; |
| 313 | *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory; |
| 314 | } |
| 315 | /* Magic for S3 resume */ |
| 316 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d); |
| 317 | } else if (boot_mode == 2) { |
| 318 | /* Failed S3 resume, reset to come up cleanly */ |
| 319 | outb(0x6, 0xcf9); |
| 320 | hlt(); |
| 321 | } else { |
| 322 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe); |
| 323 | } |
| 324 | #endif |
| 325 | post_code(0x3f); |
| 326 | #if CONFIG_CHROMEOS |
| 327 | init_chromeos(boot_mode); |
| 328 | #endif |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 329 | timestamp_add_now(TS_END_ROMSTAGE); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 330 | } |