Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; version 2 of |
| 10 | * the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 20 | * MA 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | // __PRE_RAM__ means: use "unsigned" for device, not a struct. |
| 24 | |
| 25 | #include <stdint.h> |
| 26 | #include <string.h> |
| 27 | #include <arch/io.h> |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 28 | #include <device/pci_def.h> |
| 29 | #include <device/pnp_def.h> |
| 30 | #include <cpu/x86/lapic.h> |
| 31 | #include <lib.h> |
Paul Menzel | ac6ea04 | 2013-04-29 23:21:07 +0200 | [diff] [blame] | 32 | #include <cbmem.h> |
Nico Huber | 44c392f | 2013-05-26 19:37:47 +0200 | [diff] [blame] | 33 | #include <timestamp.h> |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 34 | #include <pc80/mc146818rtc.h> |
| 35 | #include <console/console.h> |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 36 | #include <cpu/x86/bist.h> |
| 37 | #include "northbridge/intel/i945/i945.h" |
| 38 | #include "northbridge/intel/i945/raminit.h" |
| 39 | #include "southbridge/intel/i82801gx/i82801gx.h" |
| 40 | #include "dock.h" |
| 41 | |
| 42 | void setup_ich7_gpios(void) |
| 43 | { |
| 44 | printk(BIOS_DEBUG, " GPIOS..."); |
| 45 | |
| 46 | /* T60 GPIO: |
| 47 | 6: LEGACYIO# |
| 48 | 7: BDC_PRESENCE# |
| 49 | 8: H8_WAKE# |
| 50 | 10: MDI_DETECT |
| 51 | 12: H8SCI# |
| 52 | 14: CPUSB# |
| 53 | 15: CPPE# |
| 54 | 25: MDC_KILL# |
| 55 | 27: EXC_PWR_CTRL |
| 56 | 28: EXC_AUX_CTRL |
| 57 | 35: CLKREQ_SATA# |
| 58 | 36: PLANARID0 |
| 59 | 37: PLANARID1 |
| 60 | 38: PLANARID2 |
| 61 | 39: PLANARID3 |
| 62 | */ |
| 63 | outl(0x1f48f7c2, DEFAULT_GPIOBASE + 0x00); /* GPIO_USE_SEL */ |
| 64 | outl(0xe0e0ffc3, DEFAULT_GPIOBASE + 0x04); /* GP_IO_SEL */ |
| 65 | outl(0xfbfefb7d, DEFAULT_GPIOBASE + 0x0c); /* GP_LVL */ |
| 66 | /* Output Control Registers */ |
| 67 | outl(0x00040000, DEFAULT_GPIOBASE + 0x18); /* GPO_BLINK */ |
| 68 | /* Input Control Registers */ |
| 69 | outl(0x000039ff, DEFAULT_GPIOBASE + 0x2c); /* GPI_INV */ |
| 70 | outl(0x000100f0, DEFAULT_GPIOBASE + 0x30); /* GPIO_USE_SEL2 */ |
| 71 | outl(0x000000f1, DEFAULT_GPIOBASE + 0x34); /* GP_IO_SEL2 */ |
| 72 | outl(0x000300a3, DEFAULT_GPIOBASE + 0x38); /* GP_LVL2 */ |
| 73 | } |
| 74 | |
| 75 | static void ich7_enable_lpc(void) |
| 76 | { |
| 77 | // Enable Serial IRQ |
| 78 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x64, 0xd0); |
| 79 | // decode range |
| 80 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x80, 0x0210); |
| 81 | // decode range |
| 82 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x82, 0x1f0d); |
| 83 | |
| 84 | /* range 0x1600 - 0x167f */ |
| 85 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x84, 0x1601); |
| 86 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x86, 0x007c); |
| 87 | |
| 88 | /* range 0x15e0 - 0x10ef */ |
| 89 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x88, 0x15e1); |
| 90 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8a, 0x000c); |
| 91 | |
| 92 | /* range 0x1680 - 0x169f */ |
| 93 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8c, 0x1681); |
| 94 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x8e, 0x001c); |
| 95 | } |
| 96 | |
| 97 | static void early_superio_config(void) |
| 98 | { |
| 99 | int timeout = 100000; |
| 100 | device_t dev = PNP_DEV(0x2e, 3); |
| 101 | |
| 102 | pnp_write_config(dev, 0x29, 0xa0); |
| 103 | |
| 104 | while(!(pnp_read_config(dev, 0x29) & 0x10) && timeout--) |
| 105 | udelay(1000); |
| 106 | |
| 107 | /* Enable COM1 */ |
| 108 | pnp_set_logical_device(dev); |
| 109 | pnp_set_iobase(dev, PNP_IDX_IO0, 0x3f8); |
| 110 | pnp_set_enable(dev, 1); |
| 111 | } |
| 112 | |
| 113 | static void rcba_config(void) |
| 114 | { |
| 115 | /* Set up virtual channel 0 */ |
| 116 | RCBA32(0x0014) = 0x80000001; |
| 117 | RCBA32(0x001c) = 0x03128010; |
| 118 | |
| 119 | /* Device 1f interrupt pin register */ |
| 120 | RCBA32(0x3100) = 0x00001230; |
| 121 | RCBA32(0x3108) = 0x40004321; |
| 122 | |
| 123 | /* PCIe Interrupts */ |
| 124 | RCBA32(0x310c) = 0x00004321; |
| 125 | /* HD Audio Interrupt */ |
| 126 | RCBA32(0x3110) = 0x00000002; |
| 127 | |
| 128 | /* dev irq route register */ |
| 129 | RCBA16(0x3140) = 0x1007; |
| 130 | RCBA16(0x3142) = 0x0076; |
| 131 | RCBA16(0x3144) = 0x3210; |
| 132 | RCBA16(0x3146) = 0x7654; |
| 133 | RCBA16(0x3148) = 0x0010; |
| 134 | |
| 135 | /* Enable IOAPIC */ |
| 136 | RCBA8(0x31ff) = 0x03; |
| 137 | |
| 138 | /* Enable upper 128bytes of CMOS */ |
| 139 | RCBA32(0x3400) = (1 << 2); |
| 140 | |
| 141 | /* Disable unused devices */ |
| 142 | RCBA32(0x3418) = FD_PCIE6 | FD_PCIE5 | FD_INTLAN | FD_ACMOD | FD_ACAUD; |
| 143 | RCBA32(0x3418) |= (1 << 0); // Required. |
| 144 | |
| 145 | /* Set up I/O Trap #0 for 0xfe00 (SMIC) */ |
| 146 | RCBA32(0x1e84) = 0x00020001; |
| 147 | RCBA32(0x1e80) = 0x0000fe01; |
| 148 | |
| 149 | /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */ |
| 150 | RCBA32(0x1e9c) = 0x000200f0; |
| 151 | RCBA32(0x1e98) = 0x000c0801; |
| 152 | } |
| 153 | |
| 154 | static void early_ich7_init(void) |
| 155 | { |
| 156 | uint8_t reg8; |
| 157 | uint32_t reg32; |
| 158 | |
| 159 | // program secondary mlt XXX byte? |
| 160 | pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20); |
| 161 | |
| 162 | // reset rtc power status |
| 163 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4); |
| 164 | reg8 &= ~(1 << 2); |
| 165 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8); |
| 166 | |
| 167 | // usb transient disconnect |
| 168 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad); |
| 169 | reg8 |= (3 << 0); |
| 170 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8); |
| 171 | |
| 172 | reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc); |
| 173 | reg32 |= (1 << 29) | (1 << 17); |
| 174 | pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32); |
| 175 | |
| 176 | reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc); |
| 177 | reg32 |= (1 << 31) | (1 << 27); |
| 178 | pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32); |
| 179 | |
| 180 | RCBA32(0x0088) = 0x0011d000; |
| 181 | RCBA16(0x01fc) = 0x060f; |
| 182 | RCBA32(0x01f4) = 0x86000040; |
| 183 | RCBA32(0x0214) = 0x10030549; |
| 184 | RCBA32(0x0218) = 0x00020504; |
| 185 | RCBA8(0x0220) = 0xc5; |
| 186 | reg32 = RCBA32(0x3410); |
| 187 | reg32 |= (1 << 6); |
| 188 | RCBA32(0x3410) = reg32; |
| 189 | reg32 = RCBA32(0x3430); |
| 190 | reg32 &= ~(3 << 0); |
| 191 | reg32 |= (1 << 0); |
| 192 | RCBA32(0x3430) = reg32; |
| 193 | RCBA32(0x3418) |= (1 << 0); |
| 194 | RCBA16(0x0200) = 0x2008; |
| 195 | RCBA8(0x2027) = 0x0d; |
| 196 | RCBA16(0x3e08) |= (1 << 7); |
| 197 | RCBA16(0x3e48) |= (1 << 7); |
| 198 | RCBA32(0x3e0e) |= (1 << 7); |
| 199 | RCBA32(0x3e4e) |= (1 << 7); |
| 200 | |
| 201 | // next step only on ich7m b0 and later: |
| 202 | reg32 = RCBA32(0x2034); |
| 203 | reg32 &= ~(0x0f << 16); |
| 204 | reg32 |= (5 << 16); |
| 205 | RCBA32(0x2034) = reg32; |
| 206 | } |
| 207 | |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 208 | void main(unsigned long bist) |
| 209 | { |
| 210 | u32 reg32; |
Sven Schnelle | b538110 | 2011-10-15 17:31:01 +0200 | [diff] [blame] | 211 | int boot_mode = 0, dock_err; |
Paul Menzel | ac6ea04 | 2013-04-29 23:21:07 +0200 | [diff] [blame] | 212 | int cbmem_was_initted; |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 213 | const u8 spd_addrmap[2 * DIMM_SOCKETS] = { 0x50, 0x52, 0x51, 0x53 }; |
| 214 | |
Nico Huber | 44c392f | 2013-05-26 19:37:47 +0200 | [diff] [blame] | 215 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame^] | 216 | timestamp_init(get_initial_timestamp()); |
| 217 | timestamp_add_now(TS_START_ROMSTAGE); |
Nico Huber | 44c392f | 2013-05-26 19:37:47 +0200 | [diff] [blame] | 218 | |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 219 | if (bist == 0) |
| 220 | enable_lapic(); |
| 221 | |
| 222 | /* Force PCIRST# */ |
| 223 | pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR); |
| 224 | udelay(200 * 1000); |
| 225 | pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0); |
| 226 | |
| 227 | ich7_enable_lpc(); |
| 228 | |
Sven Schnelle | b538110 | 2011-10-15 17:31:01 +0200 | [diff] [blame] | 229 | /* We want early GPIO setup, to be able to detect legacy I/O module */ |
| 230 | pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1); |
| 231 | /* Enable GPIOs */ |
| 232 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); |
| 233 | setup_ich7_gpios(); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 234 | |
Sven Schnelle | b538110 | 2011-10-15 17:31:01 +0200 | [diff] [blame] | 235 | dock_err = dlpc_init(); |
| 236 | |
| 237 | /* We prefer Legacy I/O module over docking */ |
| 238 | if (legacy_io_present()) { |
| 239 | legacy_io_init(); |
| 240 | early_superio_config(); |
| 241 | } else if (!dock_err && dock_present()) { |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 242 | dock_connect(); |
| 243 | early_superio_config(); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Sven Schnelle | b538110 | 2011-10-15 17:31:01 +0200 | [diff] [blame] | 246 | /* Setup the console */ |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 247 | console_init(); |
| 248 | |
| 249 | /* Halt if there was a built in self test failure */ |
| 250 | report_bist_failure(bist); |
| 251 | |
| 252 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
| 253 | printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n"); |
| 254 | outb(0x6, 0xcf9); |
| 255 | while (1) asm("hlt"); |
| 256 | } |
| 257 | |
| 258 | /* Perform some early chipset initialization required |
| 259 | * before RAM initialization can work |
| 260 | */ |
| 261 | i945_early_initialization(); |
| 262 | |
| 263 | /* Read PM1_CNT */ |
| 264 | reg32 = inl(DEFAULT_PMBASE + 0x04); |
| 265 | printk(BIOS_DEBUG, "PM1_CNT: %08x\n", reg32); |
| 266 | if (((reg32 >> 10) & 7) == 5) { |
| 267 | #if CONFIG_HAVE_ACPI_RESUME |
| 268 | printk(BIOS_DEBUG, "Resume from S3 detected.\n"); |
| 269 | boot_mode = 2; |
| 270 | /* Clear SLP_TYPE. This will break stage2 but |
| 271 | * we care for that when we get there. |
| 272 | */ |
| 273 | outl(reg32 & ~(7 << 10), DEFAULT_PMBASE + 0x04); |
| 274 | |
| 275 | #else |
| 276 | printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n"); |
| 277 | #endif |
| 278 | } |
| 279 | |
| 280 | /* Enable SPD ROMs and DDR-II DRAM */ |
| 281 | enable_smbus(); |
| 282 | |
| 283 | #if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8 |
| 284 | dump_spd_registers(); |
| 285 | #endif |
| 286 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame^] | 287 | timestamp_add_now(TS_BEFORE_INITRAM); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 288 | sdram_initialize(boot_mode, spd_addrmap); |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame^] | 289 | timestamp_add_now(TS_AFTER_INITRAM); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 290 | |
| 291 | /* Perform some initialization that must run before stage2 */ |
| 292 | early_ich7_init(); |
| 293 | |
| 294 | /* This should probably go away. Until now it is required |
| 295 | * and mainboard specific |
| 296 | */ |
| 297 | rcba_config(); |
| 298 | |
| 299 | /* Chipset Errata! */ |
| 300 | fixup_i945_errata(); |
| 301 | |
| 302 | /* Initialize the internal PCIe links before we go into stage2 */ |
| 303 | i945_late_initialization(); |
| 304 | |
| 305 | #if !CONFIG_HAVE_ACPI_RESUME |
| 306 | #if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8 |
| 307 | #if CONFIG_DEBUG_RAM_SETUP |
| 308 | sdram_dump_mchbar_registers(); |
| 309 | |
| 310 | { |
| 311 | /* This will not work if TSEG is in place! */ |
| 312 | u32 tom = pci_read_config32(PCI_DEV(0,2,0), 0x5c); |
| 313 | |
| 314 | printk(BIOS_DEBUG, "TOM: 0x%08x\n", tom); |
| 315 | ram_check(0x00000000, 0x000a0000); |
| 316 | ram_check(0x00100000, tom); |
| 317 | } |
| 318 | #endif |
| 319 | #endif |
| 320 | #endif |
| 321 | |
| 322 | MCHBAR16(SSKPD) = 0xCAFE; |
| 323 | |
Paul Menzel | ac6ea04 | 2013-04-29 23:21:07 +0200 | [diff] [blame] | 324 | cbmem_was_initted = !cbmem_initialize(); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 325 | |
Paul Menzel | ac6ea04 | 2013-04-29 23:21:07 +0200 | [diff] [blame] | 326 | #if CONFIG_HAVE_ACPI_RESUME |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 327 | /* If there is no high memory area, we didn't boot before, so |
| 328 | * this is not a resume. In that case we just create the cbmem toc. |
| 329 | */ |
Paul Menzel | ac6ea04 | 2013-04-29 23:21:07 +0200 | [diff] [blame] | 330 | if ((boot_mode == 2) && cbmem_was_initted) { |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 331 | void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME); |
| 332 | |
| 333 | /* copy 1MB - 64K to high tables ram_base to prevent memory corruption |
| 334 | * through stage 2. We could keep stuff like stack and heap in high tables |
| 335 | * memory completely, but that's a wonderful clean up task for another |
| 336 | * day. |
| 337 | */ |
| 338 | if (resume_backup_memory) |
| 339 | memcpy(resume_backup_memory, (void *)CONFIG_RAMBASE, HIGH_MEMORY_SAVE); |
| 340 | |
| 341 | /* Magic for S3 resume */ |
Sven Schnelle | d8c68a9 | 2011-06-15 09:26:34 +0200 | [diff] [blame] | 342 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, SKPAD_ACPI_S3_MAGIC); |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 343 | } |
| 344 | #endif |
Paul Menzel | ac6ea04 | 2013-04-29 23:21:07 +0200 | [diff] [blame] | 345 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame^] | 346 | timestamp_sync(); |
Nico Huber | 44c392f | 2013-05-26 19:37:47 +0200 | [diff] [blame] | 347 | timestamp_add_now(TS_END_ROMSTAGE); |
Nico Huber | 44c392f | 2013-05-26 19:37:47 +0200 | [diff] [blame] | 348 | |
Paul Menzel | ac6ea04 | 2013-04-29 23:21:07 +0200 | [diff] [blame] | 349 | #if CONFIG_CONSOLE_CBMEM |
| 350 | /* Keep this the last thing this function does. */ |
| 351 | cbmemc_reinit(); |
| 352 | #endif |
Sven Schnelle | d8129f9 | 2011-04-20 09:12:17 +0000 | [diff] [blame] | 353 | } |