Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 3 | * |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007-2008 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
Uwe Hermann | 2d2f0c1 | 2009-10-28 17:36:11 +0000 | [diff] [blame] | 8 | * published by the Free Software Foundation; version 2 of the License. |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
Myles Watson | 1d6d45e | 2009-11-06 17:02:51 +0000 | [diff] [blame] | 16 | // __PRE_RAM__ means: use "unsigned" for device, not a struct. |
Stefan Reinauer | 5e32823 | 2010-03-29 19:19:16 +0000 | [diff] [blame] | 17 | |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | #include <string.h> |
| 20 | #include <arch/io.h> |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 21 | #include <device/pci_def.h> |
| 22 | #include <device/pnp_def.h> |
| 23 | #include <cpu/x86/lapic.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 24 | #include <lib.h> |
Kyösti Mälkki | 12d681b | 2014-06-14 18:51:34 +0300 | [diff] [blame] | 25 | #include <arch/acpi.h> |
Kyösti Mälkki | a7c9611 | 2013-10-13 20:41:57 +0300 | [diff] [blame] | 26 | #include <cbmem.h> |
Paul Menzel | 6c20b65 | 2016-12-29 22:54:02 +0100 | [diff] [blame] | 27 | #include <timestamp.h> |
Edward O'Callaghan | cf5ac3d | 2014-06-03 08:40:34 +1000 | [diff] [blame] | 28 | #include <superio/smsc/lpc47m15x/lpc47m15x.h> |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 29 | #include <pc80/mc146818rtc.h> |
Stefan Reinauer | 8a7d34b | 2010-02-22 09:15:13 +0000 | [diff] [blame] | 30 | #include <console/console.h> |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 31 | #include <cpu/x86/bist.h> |
Kyösti Mälkki | 408d392 | 2016-06-17 10:43:48 +0300 | [diff] [blame] | 32 | #include <cpu/intel/romstage.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 33 | #include <northbridge/intel/i945/i945.h> |
| 34 | #include <northbridge/intel/i945/raminit.h> |
| 35 | #include <southbridge/intel/i82801gx/i82801gx.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 36 | |
Edward O'Callaghan | cf5ac3d | 2014-06-03 08:40:34 +1000 | [diff] [blame] | 37 | #define SERIAL_DEV PNP_DEV(0x2e, LPC47M15X_SP1) |
| 38 | #define PME_DEV PNP_DEV(0x2e, LPC47M15X_PME) |
Uwe Hermann | 57b2ff8 | 2010-11-21 17:29:59 +0000 | [diff] [blame] | 39 | |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 40 | static void ich7_enable_lpc(void) |
| 41 | { |
| 42 | // Enable Serial IRQ |
| 43 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x64, 0xd0); |
| 44 | // Set COM1/COM2 decode range |
| 45 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x80, 0x0010); |
| 46 | // Enable COM1 |
| 47 | pci_write_config16(PCI_DEV(0, 0x1f, 0), 0x82, 0x140d); |
| 48 | // Enable SuperIO Power Management Events |
| 49 | pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x84, 0x007c0681); |
| 50 | } |
| 51 | |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 52 | static void rcba_config(void) |
| 53 | { |
| 54 | /* Set up virtual channel 0 */ |
| 55 | //RCBA32(0x0014) = 0x80000001; |
| 56 | //RCBA32(0x001c) = 0x03128010; |
| 57 | |
| 58 | /* Device 1f interrupt pin register */ |
| 59 | RCBA32(0x3100) = 0x00042210; |
| 60 | /* Device 1d interrupt pin register */ |
| 61 | RCBA32(0x310c) = 0x00214321; |
| 62 | |
| 63 | /* dev irq route register */ |
| 64 | RCBA16(0x3140) = 0x0132; |
| 65 | RCBA16(0x3142) = 0x0146; |
| 66 | RCBA16(0x3144) = 0x0237; |
| 67 | RCBA16(0x3146) = 0x3201; |
| 68 | RCBA16(0x3148) = 0x0146; |
| 69 | |
| 70 | /* Enable IOAPIC */ |
| 71 | RCBA8(0x31ff) = 0x03; |
| 72 | |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 73 | /* Disable unused devices */ |
| 74 | //RCBA32(0x3418) = FD_PCIE6|FD_PCIE5|FD_PCIE4|FD_ACMOD|FD_ACAUD|FD_PATA; |
| 75 | // RCBA32(0x3418) |= (1 << 0); // Required. |
| 76 | // FIXME look me up! |
| 77 | RCBA32(0x3418) = 0x003204e1; |
| 78 | |
| 79 | /* Enable PCIe Root Port Clock Gate */ |
| 80 | // RCBA32(0x341c) = 0x00000001; |
| 81 | } |
| 82 | |
| 83 | static void early_ich7_init(void) |
| 84 | { |
| 85 | uint8_t reg8; |
| 86 | uint32_t reg32; |
| 87 | |
| 88 | // program secondary mlt XXX byte? |
| 89 | pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20); |
| 90 | |
| 91 | // reset rtc power status |
| 92 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4); |
| 93 | reg8 &= ~(1 << 2); |
| 94 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8); |
| 95 | |
| 96 | // usb transient disconnect |
| 97 | reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad); |
| 98 | reg8 |= (3 << 0); |
| 99 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8); |
| 100 | |
| 101 | reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc); |
| 102 | reg32 |= (1 << 29) | (1 << 17); |
| 103 | pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32); |
| 104 | |
| 105 | reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc); |
| 106 | reg32 |= (1 << 31) | (1 << 27); |
| 107 | pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32); |
| 108 | |
| 109 | RCBA32(0x0088) = 0x0011d000; |
| 110 | RCBA16(0x01fc) = 0x060f; |
| 111 | RCBA32(0x01f4) = 0x86000040; |
| 112 | RCBA32(0x0214) = 0x10030549; |
| 113 | RCBA32(0x0218) = 0x00020504; |
| 114 | RCBA8(0x0220) = 0xc5; |
| 115 | reg32 = RCBA32(0x3410); |
| 116 | reg32 |= (1 << 6); |
| 117 | RCBA32(0x3410) = reg32; |
| 118 | reg32 = RCBA32(0x3430); |
| 119 | reg32 &= ~(3 << 0); |
| 120 | reg32 |= (1 << 0); |
| 121 | RCBA32(0x3430) = reg32; |
| 122 | RCBA32(0x3418) |= (1 << 0); |
| 123 | RCBA16(0x0200) = 0x2008; |
| 124 | RCBA8(0x2027) = 0x0d; |
| 125 | RCBA16(0x3e08) |= (1 << 7); |
| 126 | RCBA16(0x3e48) |= (1 << 7); |
| 127 | RCBA32(0x3e0e) |= (1 << 7); |
| 128 | RCBA32(0x3e4e) |= (1 << 7); |
| 129 | |
| 130 | // next step only on ich7m b0 and later: |
| 131 | reg32 = RCBA32(0x2034); |
| 132 | reg32 &= ~(0x0f << 16); |
| 133 | reg32 |= (5 << 16); |
| 134 | RCBA32(0x2034) = reg32; |
| 135 | } |
| 136 | |
Kyösti Mälkki | 408d392 | 2016-06-17 10:43:48 +0300 | [diff] [blame] | 137 | void mainboard_romstage_entry(unsigned long bist) |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 138 | { |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 139 | int s3resume = 0, boot_mode = 0; |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 140 | |
Paul Menzel | 6c20b65 | 2016-12-29 22:54:02 +0100 | [diff] [blame] | 141 | |
| 142 | timestamp_init(get_initial_timestamp()); |
| 143 | timestamp_add_now(TS_START_ROMSTAGE); |
| 144 | |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 145 | if (bist == 0) |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 146 | enable_lapic(); |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 147 | |
| 148 | ich7_enable_lpc(); |
Edward O'Callaghan | cf5ac3d | 2014-06-03 08:40:34 +1000 | [diff] [blame] | 149 | /* Enable SuperIO PM */ |
| 150 | lpc47m15x_enable_serial(PME_DEV, 0x680); |
| 151 | lpc47m15x_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); /* 0x3f8 */ |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 152 | |
| 153 | /* Set up the console */ |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 154 | console_init(); |
| 155 | |
| 156 | /* Halt if there was a built in self test failure */ |
| 157 | report_bist_failure(bist); |
| 158 | |
| 159 | if (MCHBAR16(SSKPD) == 0xCAFE) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 160 | printk(BIOS_DEBUG, "soft reset detected.\n"); |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 161 | boot_mode = 1; |
| 162 | } |
| 163 | |
| 164 | /* Perform some early chipset initialization required |
| 165 | * before RAM initialization can work |
| 166 | */ |
| 167 | i945_early_initialization(); |
| 168 | |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 169 | s3resume = southbridge_detect_s3_resume(); |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 170 | |
| 171 | /* Enable SPD ROMs and DDR-II DRAM */ |
| 172 | enable_smbus(); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 173 | |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 174 | #if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8 |
| 175 | dump_spd_registers(); |
| 176 | #endif |
| 177 | |
Paul Menzel | 6c20b65 | 2016-12-29 22:54:02 +0100 | [diff] [blame] | 178 | timestamp_add_now(TS_BEFORE_INITRAM); |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 179 | sdram_initialize(s3resume ? 2 : boot_mode, NULL); |
Paul Menzel | 6c20b65 | 2016-12-29 22:54:02 +0100 | [diff] [blame] | 180 | timestamp_add_now(TS_AFTER_INITRAM); |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 181 | |
| 182 | /* Perform some initialization that must run before stage2 */ |
| 183 | early_ich7_init(); |
| 184 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 185 | /* This should probably go away. Until now it is required |
| 186 | * and mainboard specific |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 187 | */ |
| 188 | rcba_config(); |
| 189 | |
| 190 | /* Chipset Errata! */ |
| 191 | fixup_i945_errata(); |
| 192 | |
| 193 | /* Initialize the internal PCIe links before we go into stage2 */ |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 194 | i945_late_initialization(s3resume); |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 195 | } |