Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +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> |
| 26 | #include <arch/romcc_io.h> |
| 27 | #include <device/pci_def.h> |
| 28 | #include <device/pnp_def.h> |
| 29 | #include <cpu/x86/lapic.h> |
| 30 | #include <pc80/mc146818rtc.h> |
| 31 | #include <cbmem.h> |
| 32 | #include <console/console.h> |
| 33 | #include "superio/ite/it8772f/it8772f.h" |
| 34 | #include "superio/ite/it8772f/early_serial.c" |
| 35 | #include "northbridge/intel/sandybridge/sandybridge.h" |
| 36 | #include "northbridge/intel/sandybridge/raminit.h" |
| 37 | #include "southbridge/intel/bd82x6x/pch.h" |
| 38 | #include "southbridge/intel/bd82x6x/gpio.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_CONSOLE_SERIAL8250 |
| 44 | #include "superio/smsc/lpc47n207/lpc47n207.h" |
| 45 | #include "superio/smsc/lpc47n207/early_serial.c" |
| 46 | #endif |
| 47 | #if CONFIG_CHROMEOS |
| 48 | #include <vendorcode/google/chromeos/chromeos.h> |
| 49 | #endif |
| 50 | |
| 51 | /* Stumpy USB Reset Disable defined in cmos.layout */ |
| 52 | #if CONFIG_USE_OPTION_TABLE |
| 53 | #include "option_table.h" |
| 54 | #define CMOS_USB_RESET_DISABLE (CMOS_VSTART_stumpy_usb_reset_disable >> 3) |
| 55 | #else |
| 56 | #define CMOS_USB_RESET_DISABLE (400 >> 3) |
| 57 | #endif |
| 58 | #define USB_RESET_DISABLE_MAGIC (0xdd) /* Disable if set to this */ |
| 59 | |
| 60 | static void pch_enable_lpc(void) |
| 61 | { |
| 62 | /* Set COM1/COM2 decode range */ |
| 63 | pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010); |
| 64 | |
| 65 | #if CONFIG_CONSOLE_SERIAL8250 |
| 66 | /* Enable SuperIO + PS/2 Keyboard/Mouse + COM1 + lpc47n207 config*/ |
| 67 | pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN |\ |
| 68 | CNF2_LPC_EN | COMA_LPC_EN); |
| 69 | |
| 70 | /* map full 256 bytes at 0x1600 to the LPC bus */ |
| 71 | pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, 0xfc1601); |
| 72 | |
| 73 | try_enabling_LPC47N207_uart(); |
| 74 | #else |
| 75 | /* Enable SuperIO + PS/2 Keyboard/Mouse */ |
| 76 | pci_write_config16(PCH_LPC_DEV, LPC_EN, CNF1_LPC_EN | KBC_LPC_EN); |
| 77 | #endif |
| 78 | } |
| 79 | |
| 80 | static void rcba_config(void) |
| 81 | { |
| 82 | u32 reg32; |
| 83 | |
| 84 | /* |
| 85 | * GFX INTA -> PIRQA (MSI) |
| 86 | * D28IP_P1IP WLAN INTA -> PIRQB |
| 87 | * D28IP_P4IP ETH0 INTB -> PIRQC |
| 88 | * D29IP_E1P EHCI1 INTA -> PIRQD |
| 89 | * D26IP_E2P EHCI2 INTA -> PIRQE |
| 90 | * D31IP_SIP SATA INTA -> PIRQF (MSI) |
| 91 | * D31IP_SMIP SMBUS INTB -> PIRQG |
| 92 | * D31IP_TTIP THRT INTC -> PIRQH |
| 93 | * D27IP_ZIP HDA INTA -> PIRQG (MSI) |
| 94 | */ |
| 95 | |
| 96 | /* Device interrupt pin register (board specific) */ |
| 97 | RCBA32(D31IP) = (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) | |
| 98 | (INTB << D31IP_SMIP) | (INTA << D31IP_SIP); |
| 99 | RCBA32(D30IP) = (NOINT << D30IP_PIP); |
| 100 | RCBA32(D29IP) = (INTA << D29IP_E1P); |
| 101 | RCBA32(D28IP) = (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) | |
| 102 | (INTB << D28IP_P4IP); |
| 103 | RCBA32(D27IP) = (INTA << D27IP_ZIP); |
| 104 | RCBA32(D26IP) = (INTA << D26IP_E2P); |
| 105 | RCBA32(D25IP) = (NOINT << D25IP_LIP); |
| 106 | RCBA32(D22IP) = (NOINT << D22IP_MEI1IP); |
| 107 | |
| 108 | /* Device interrupt route registers */ |
| 109 | DIR_ROUTE(D31IR, PIRQF, PIRQG, PIRQH, PIRQA); |
| 110 | DIR_ROUTE(D29IR, PIRQD, PIRQE, PIRQF, PIRQG); |
| 111 | DIR_ROUTE(D28IR, PIRQB, PIRQC, PIRQD, PIRQE); |
| 112 | DIR_ROUTE(D27IR, PIRQG, PIRQH, PIRQA, PIRQB); |
| 113 | DIR_ROUTE(D26IR, PIRQE, PIRQF, PIRQG, PIRQH); |
| 114 | DIR_ROUTE(D25IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 115 | DIR_ROUTE(D22IR, PIRQA, PIRQB, PIRQC, PIRQD); |
| 116 | |
| 117 | /* Enable IOAPIC (generic) */ |
| 118 | RCBA16(OIC) = 0x0100; |
| 119 | /* PCH BWG says to read back the IOAPIC enable register */ |
| 120 | (void) RCBA16(OIC); |
| 121 | |
| 122 | /* Enable upper 128bytes of CMOS (generic) */ |
| 123 | RCBA32(RC) = (1 << 2); |
| 124 | |
| 125 | /* Disable unused devices (board specific) */ |
| 126 | reg32 = RCBA32(FD); |
| 127 | reg32 |= PCH_DISABLE_ALWAYS; |
| 128 | RCBA32(FD) = reg32; |
| 129 | } |
| 130 | |
| 131 | static void early_pch_init(void) |
| 132 | { |
| 133 | u8 reg8; |
| 134 | |
| 135 | // reset rtc power status |
| 136 | reg8 = pci_read_config8(PCH_LPC_DEV, 0xa4); |
| 137 | reg8 &= ~(1 << 2); |
| 138 | pci_write_config8(PCH_LPC_DEV, 0xa4, reg8); |
| 139 | } |
| 140 | |
| 141 | static void setup_sio_gpios(void) |
| 142 | { |
| 143 | /* |
| 144 | * GPIO10 as USBPWRON12# |
| 145 | * GPIO12 as USBPWRON13# |
| 146 | */ |
| 147 | it8772f_gpio_setup(1, 0x05, 0x05, 0x00, 0x05, 0x05); |
| 148 | |
| 149 | /* |
| 150 | * GPIO22 as wake SCI# |
| 151 | */ |
| 152 | it8772f_gpio_setup(2, 0x04, 0x04, 0x00, 0x04, 0x04); |
| 153 | |
| 154 | /* |
| 155 | * GPIO32 as EXTSMI# |
| 156 | */ |
| 157 | it8772f_gpio_setup(3, 0x04, 0x04, 0x00, 0x04, 0x04); |
| 158 | |
| 159 | /* |
| 160 | * GPIO45 as LED_POWER# |
| 161 | */ |
| 162 | it8772f_gpio_setup(4, 0x20, 0x20, 0x20, 0x20, 0x20); |
| 163 | |
| 164 | /* |
| 165 | * GPIO51 as USBPWRON8# |
| 166 | * GPIO52 as USBPWRON1# |
| 167 | */ |
| 168 | it8772f_gpio_setup(5, 0x06, 0x06, 0x00, 0x06, 0x06); |
| 169 | it8772f_gpio_setup(6, 0x00, 0x00, 0x00, 0x00, 0x00); |
| 170 | } |
| 171 | |
| 172 | void main(unsigned long bist) |
| 173 | { |
| 174 | int boot_mode = 0; |
| 175 | int cbmem_was_initted; |
| 176 | u32 pm1_cnt; |
| 177 | u16 pm1_sts; |
| 178 | |
| 179 | #if CONFIG_COLLECT_TIMESTAMPS |
| 180 | tsc_t start_romstage_time; |
| 181 | tsc_t before_dram_time; |
| 182 | tsc_t after_dram_time; |
| 183 | tsc_t base_time = { |
| 184 | .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc), |
| 185 | .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) |
| 186 | }; |
| 187 | #endif |
| 188 | struct pei_data pei_data = { |
| 189 | mchbar: 0xfed10000, |
| 190 | dmibar: 0xfed18000, |
| 191 | epbar: 0xfed19000, |
| 192 | pciexbar: 0xf0000000, |
| 193 | smbusbar: 0x400, |
| 194 | wdbbar: 0x4000000, |
| 195 | wdbsize: 0x1000, |
| 196 | hpet_address: 0xfed00000, |
| 197 | rcba: 0xfed1c000, |
| 198 | pmbase: 0x500, |
| 199 | gpiobase: 0x480, |
| 200 | thermalbase: 0xfed08000, |
| 201 | system_type: 0, // 0 Mobile, 1 Desktop/Server |
| 202 | tseg_size: CONFIG_SMM_TSEG_SIZE, |
| 203 | spd_addresses: { 0x50, 0x00,0x52,0x00 }, |
| 204 | ts_addresses: { 0x00, 0x00, 0x00, 0x00 }, |
| 205 | ec_present: 0, |
| 206 | // 0 = leave channel enabled |
| 207 | // 1 = disable dimm 0 on channel |
| 208 | // 2 = disable dimm 1 on channel |
| 209 | // 3 = disable dimm 0+1 on channel |
| 210 | dimm_channel0_disabled: 2, |
| 211 | dimm_channel1_disabled: 2, |
| 212 | usb_port_config: { |
| 213 | { 1, 0, 0x0080 }, /* P0: Front port (OC0) */ |
| 214 | { 1, 1, 0x0040 }, /* P1: Back port (OC1) */ |
| 215 | { 1, 0, 0x0040 }, /* P2: MINIPCIE1 (no OC) */ |
| 216 | { 1, 0, 0x0040 }, /* P3: MMC (no OC) */ |
| 217 | { 1, 2, 0x0080 }, /* P4: Front port (OC2) */ |
| 218 | { 0, 0, 0x0000 }, /* P5: Empty */ |
| 219 | { 0, 0, 0x0000 }, /* P6: Empty */ |
| 220 | { 0, 0, 0x0000 }, /* P7: Empty */ |
| 221 | { 1, 4, 0x0040 }, /* P8: Back port (OC4) */ |
| 222 | { 1, 4, 0x0040 }, /* P9: MINIPCIE3 (no OC) */ |
| 223 | { 1, 4, 0x0040 }, /* P10: BLUETOOTH (no OC) */ |
| 224 | { 0, 4, 0x0000 }, /* P11: Empty */ |
| 225 | { 1, 6, 0x0040 }, /* P12: Back port (OC6) */ |
| 226 | { 1, 5, 0x0040 }, /* P13: Back port (OC5) */ |
| 227 | }, |
| 228 | }; |
| 229 | |
| 230 | #if CONFIG_COLLECT_TIMESTAMPS |
| 231 | start_romstage_time = rdtsc(); |
| 232 | #endif |
| 233 | |
| 234 | if (bist == 0) |
| 235 | enable_lapic(); |
| 236 | |
| 237 | pch_enable_lpc(); |
| 238 | |
| 239 | /* Enable GPIOs */ |
| 240 | pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE|1); |
| 241 | pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10); |
| 242 | setup_pch_gpios(&stumpy_gpio_map); |
| 243 | setup_sio_gpios(); |
| 244 | |
| 245 | /* Early SuperIO setup */ |
| 246 | it8772f_kill_watchdog(); |
| 247 | it8772f_ac_resume_southbridge(); |
| 248 | it8772f_enable_serial(PNP_DEV(IT8772F_BASE, IT8772F_SP1), |
| 249 | CONFIG_TTYS0_BASE); |
| 250 | console_init(); |
| 251 | |
| 252 | #if CONFIG_CHROMEOS |
| 253 | save_chromeos_gpios(); |
| 254 | #endif |
| 255 | |
| 256 | /* Halt if there was a built in self test failure */ |
| 257 | report_bist_failure(bist); |
| 258 | |
| 259 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 260 | printk(BIOS_DEBUG, "soft reset detected\n"); |
| 261 | boot_mode = 1; |
| 262 | |
| 263 | /* System is not happy after keyboard reset... */ |
| 264 | printk(BIOS_DEBUG, "Issuing CF9 warm reset\n"); |
| 265 | outb(0x6, 0xcf9); |
| 266 | hlt(); |
| 267 | } |
| 268 | |
| 269 | /* Perform some early chipset initialization required |
| 270 | * before RAM initialization can work |
| 271 | */ |
| 272 | sandybridge_early_initialization(SANDYBRIDGE_MOBILE); |
| 273 | printk(BIOS_DEBUG, "Back from sandybridge_early_initialization()\n"); |
| 274 | |
| 275 | /* Check PM1_STS[15] to see if we are waking from Sx */ |
| 276 | pm1_sts = inw(DEFAULT_PMBASE + PM1_STS); |
| 277 | |
| 278 | /* Read PM1_CNT[12:10] to determine which Sx state */ |
| 279 | pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT); |
| 280 | |
| 281 | if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) { |
| 282 | #if CONFIG_HAVE_ACPI_RESUME |
| 283 | printk(BIOS_DEBUG, "Resume from S3 detected.\n"); |
| 284 | boot_mode = 2; |
| 285 | /* Clear SLP_TYPE. This will break stage2 but |
| 286 | * we care for that when we get there. |
| 287 | */ |
| 288 | outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + PM1_CNT); |
| 289 | #else |
| 290 | printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n"); |
| 291 | #endif |
| 292 | } |
| 293 | |
| 294 | post_code(0x38); |
| 295 | /* Enable SPD ROMs and DDR-III DRAM */ |
| 296 | enable_smbus(); |
| 297 | |
| 298 | /* Prepare USB controller early in S3 resume */ |
| 299 | if (boot_mode == 2) { |
| 300 | /* |
| 301 | * For Stumpy the back USB ports are reset on resume |
| 302 | * so default to resetting the controller to make the |
| 303 | * kernel happy. There is a CMOS flag to disable the |
| 304 | * controller reset in case the kernel can tolerate |
| 305 | * the device power loss better in the future. |
| 306 | */ |
| 307 | u8 magic = cmos_read(CMOS_USB_RESET_DISABLE); |
| 308 | |
| 309 | if (magic == USB_RESET_DISABLE_MAGIC) { |
| 310 | printk(BIOS_DEBUG, "USB Controller Reset Disabled\n"); |
| 311 | enable_usb_bar(); |
| 312 | } else { |
| 313 | printk(BIOS_DEBUG, "USB Controller Reset Enabled\n"); |
| 314 | } |
| 315 | } else { |
| 316 | /* Ensure USB reset on resume is enabled at boot */ |
| 317 | cmos_write(0, CMOS_USB_RESET_DISABLE); |
| 318 | } |
| 319 | |
| 320 | post_code(0x39); |
| 321 | pei_data.boot_mode = boot_mode; |
| 322 | #if CONFIG_COLLECT_TIMESTAMPS |
| 323 | before_dram_time = rdtsc(); |
| 324 | #endif |
| 325 | sdram_initialize(&pei_data); |
| 326 | |
| 327 | #if CONFIG_COLLECT_TIMESTAMPS |
| 328 | after_dram_time = rdtsc(); |
| 329 | #endif |
| 330 | post_code(0x3a); |
| 331 | /* Perform some initialization that must run before stage2 */ |
| 332 | early_pch_init(); |
| 333 | post_code(0x3b); |
| 334 | |
| 335 | rcba_config(); |
| 336 | post_code(0x3c); |
| 337 | |
| 338 | /* Initialize the internal PCIe links before we go into stage2 */ |
| 339 | sandybridge_late_initialization(); |
| 340 | |
| 341 | post_code(0x3e); |
| 342 | quick_ram_check(); |
| 343 | |
| 344 | MCHBAR16(SSKPD) = 0xCAFE; |
| 345 | #if CONFIG_EARLY_CBMEM_INIT |
| 346 | cbmem_was_initted = !cbmem_initialize(); |
| 347 | #else |
| 348 | cbmem_was_initted = cbmem_reinit((uint64_t) (get_top_of_ram() |
| 349 | - HIGH_MEMORY_SIZE)); |
| 350 | #endif |
| 351 | |
| 352 | #if CONFIG_HAVE_ACPI_RESUME |
| 353 | /* If there is no high memory area, we didn't boot before, so |
| 354 | * this is not a resume. In that case we just create the cbmem toc. |
| 355 | */ |
| 356 | |
| 357 | *(u32 *)CBMEM_BOOT_MODE = 0; |
| 358 | *(u32 *)CBMEM_RESUME_BACKUP = 0; |
| 359 | |
| 360 | if ((boot_mode == 2) && cbmem_was_initted) { |
| 361 | void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME); |
| 362 | if (resume_backup_memory) { |
| 363 | *(u32 *)CBMEM_BOOT_MODE = boot_mode; |
| 364 | *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory; |
| 365 | } |
| 366 | /* Magic for S3 resume */ |
| 367 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d); |
| 368 | } else if (boot_mode == 2) { |
| 369 | /* Failed S3 resume, reset to come up cleanly */ |
| 370 | outb(0x6, 0xcf9); |
| 371 | hlt(); |
| 372 | } else { |
| 373 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe); |
| 374 | } |
| 375 | #endif |
| 376 | post_code(0x3f); |
| 377 | #if CONFIG_CHROMEOS |
| 378 | init_chromeos(boot_mode); |
| 379 | #endif |
| 380 | #if CONFIG_COLLECT_TIMESTAMPS |
| 381 | timestamp_init(base_time); |
| 382 | timestamp_add(TS_START_ROMSTAGE, start_romstage_time ); |
| 383 | timestamp_add(TS_BEFORE_INITRAM, before_dram_time ); |
| 384 | timestamp_add(TS_AFTER_INITRAM, after_dram_time ); |
| 385 | timestamp_add_now(TS_END_ROMSTAGE); |
| 386 | #endif |
| 387 | #if CONFIG_CONSOLE_CBMEM |
| 388 | /* Keep this the last thing this function does. */ |
| 389 | cbmemc_reinit(); |
| 390 | #endif |
| 391 | } |