blob: b4611f5bcca0dd7d4b43c0897397a0442c4172d1 [file] [log] [blame]
Stefan Reinauer838c5a52010-01-17 14:08:17 +00001/*
2 * This file is part of the coreboot project.
Stefan Reinauer14e22772010-04-27 06:56:47 +00003 *
Stefan Reinauer838c5a52010-01-17 14:08:17 +00004 * Copyright (C) 2007-2009 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
8 * published by the Free Software Foundation; version 2 of
9 * 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.
Stefan Reinauer838c5a52010-01-17 14:08:17 +000015 */
16
Elyes HAOUASec16e932016-10-07 18:22:44 +020017/* __PRE_RAM__ means: use "unsigned" for device, not a struct. */
Stefan Reinauer5e328232010-03-29 19:19:16 +000018
Stefan Reinauer838c5a52010-01-17 14:08:17 +000019#include <stdint.h>
20#include <string.h>
21#include <arch/io.h>
Stefan Reinauer838c5a52010-01-17 14:08:17 +000022#include <device/pci_def.h>
23#include <device/pnp_def.h>
24#include <cpu/x86/lapic.h>
Patrick Georgid0835952010-10-05 09:07:10 +000025#include <lib.h>
Kyösti Mälkki12d681b2014-06-14 18:51:34 +030026#include <arch/acpi.h>
Kyösti Mälkkia7c96112013-10-13 20:41:57 +030027#include <cbmem.h>
Paul Menzel6c20b652016-12-29 22:54:02 +010028#include <timestamp.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000029#include <pc80/mc146818rtc.h>
Stefan Reinauer8a7d34b2010-02-22 09:15:13 +000030#include <console/console.h>
Stefan Reinauer838c5a52010-01-17 14:08:17 +000031#include <cpu/x86/bist.h>
Kyösti Mälkki15fa9922016-06-17 10:00:28 +030032#include <cpu/intel/romstage.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010033#include <halt.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110034#include <northbridge/intel/i945/i945.h>
35#include <northbridge/intel/i945/raminit.h>
36#include <southbridge/intel/i82801gx/i82801gx.h>
Patrick Georgia4700192011-01-27 07:39:38 +000037#include "option_table.h"
Patrick Georgid0835952010-10-05 09:07:10 +000038
Stefan Reinauer838c5a52010-01-17 14:08:17 +000039static void ich7_enable_lpc(void)
40{
Patrick Georgia4700192011-01-27 07:39:38 +000041 int lpt_en = 0;
Arthur Heymansb451df22017-08-15 20:59:09 +020042 if (read_option(lpt, 0) != 0)
43 lpt_en = LPT_LPC_EN; /* enable LPT */
44
Elyes HAOUASec16e932016-10-07 18:22:44 +020045 /* Enable Serial IRQ */
Arthur Heymansb451df22017-08-15 20:59:09 +020046 pci_write_config8(PCI_DEV(0, 0x1f, 0), SERIRQ_CNTL, 0xd0);
Elyes HAOUASec16e932016-10-07 18:22:44 +020047 /* decode range */
Arthur Heymansb451df22017-08-15 20:59:09 +020048 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_IO_DEC, 0x0007);
Elyes HAOUASec16e932016-10-07 18:22:44 +020049 /* decode range */
Arthur Heymansb451df22017-08-15 20:59:09 +020050 pci_write_config16(PCI_DEV(0, 0x1f, 0), LPC_EN, CNF2_LPC_EN | CNF1_LPC_EN
51 | MC_LPC_EN | KBC_LPC_EN | GAMEH_LPC_EN | GAMEL_LPC_EN
52 | FDD_LPC_EN | lpt_en | COMB_LPC_EN | COMA_LPC_EN);
53 /* COM3 and COM4 decode? */
54 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN1_DEC, 0x1c02e1);
55 /* ??decode?? */
56 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN2_DEC, 0x00fc0601);
57 /* EC decode? */
58 pci_write_config32(PCI_DEV(0, 0x1f, 0), GEN3_DEC, 0x00040069);
Stefan Reinauer838c5a52010-01-17 14:08:17 +000059}
60
Stefan Reinauer838c5a52010-01-17 14:08:17 +000061/* This box has two superios, so enabling serial becomes slightly excessive.
62 * We disable a lot of stuff to make sure that there are no conflicts between
63 * the two. Also set up the GPIOs from the beginning. This is the "no schematic
64 * but safe anyways" method.
65 */
Antonello Dettori63028fd2016-11-08 18:44:46 +010066static inline void pnp_enter_ext_func_mode(pnp_devfn_t dev)
Stefan Reinauer838c5a52010-01-17 14:08:17 +000067{
68 unsigned int port = dev >> 8;
69 outb(0x55, port);
70}
71
Antonello Dettori63028fd2016-11-08 18:44:46 +010072static void pnp_exit_ext_func_mode(pnp_devfn_t dev)
Stefan Reinauer838c5a52010-01-17 14:08:17 +000073{
74 unsigned int port = dev >> 8;
75 outb(0xaa, port);
76}
77
Antonello Dettori63028fd2016-11-08 18:44:46 +010078static void pnp_write_register(pnp_devfn_t dev, int reg, int val)
Stefan Reinauer838c5a52010-01-17 14:08:17 +000079{
80 unsigned int port = dev >> 8;
81 outb(reg, port);
82 outb(val, port+1);
83}
84
85static void early_superio_config(void)
86{
Antonello Dettori63028fd2016-11-08 18:44:46 +010087 pnp_devfn_t dev;
Stefan Reinauer838c5a52010-01-17 14:08:17 +000088
Elyes HAOUASa5aad2e2016-09-19 09:47:16 -060089 dev = PNP_DEV(0x2e, 0x00);
Stefan Reinauer838c5a52010-01-17 14:08:17 +000090
91 pnp_enter_ext_func_mode(dev);
Elyes HAOUASec16e932016-10-07 18:22:44 +020092 pnp_write_register(dev, 0x01, 0x94); /* Extended Parport modes */
93 pnp_write_register(dev, 0x02, 0x88); /* UART power on */
94 pnp_write_register(dev, 0x03, 0x72); /* Floppy */
95 pnp_write_register(dev, 0x04, 0x01); /* EPP + SPP */
96 pnp_write_register(dev, 0x14, 0x03); /* Floppy */
97 pnp_write_register(dev, 0x20, (0x3f0 >> 2)); /* Floppy */
98 pnp_write_register(dev, 0x23, (0x378 >> 2)); /* PP base */
99 pnp_write_register(dev, 0x24, (0x3f8 >> 2)); /* UART1 base */
100 pnp_write_register(dev, 0x25, (0x2f8 >> 2)); /* UART2 base */
101 pnp_write_register(dev, 0x26, (2 << 4) | 0); /* FDC + PP DMA */
102 pnp_write_register(dev, 0x27, (6 << 4) | 7); /* FDC + PP DMA */
103 pnp_write_register(dev, 0x28, (4 << 4) | 3); /* UART1,2 IRQ */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000104 /* These are the SMI status registers in the SIO: */
Elyes HAOUASec16e932016-10-07 18:22:44 +0200105 pnp_write_register(dev, 0x30, (0x600 >> 4)); /* Runtime Register Block Base */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000106
Elyes HAOUASec16e932016-10-07 18:22:44 +0200107 pnp_write_register(dev, 0x31, 0x00); /* GPIO1 DIR */
108 pnp_write_register(dev, 0x32, 0x00); /* GPIO1 POL */
109 pnp_write_register(dev, 0x33, 0x40); /* GPIO2 DIR */
110 pnp_write_register(dev, 0x34, 0x00); /* GPIO2 POL */
111 pnp_write_register(dev, 0x35, 0xff); /* GPIO3 DIR */
112 pnp_write_register(dev, 0x36, 0x00); /* GPIO3 POL */
113 pnp_write_register(dev, 0x37, 0xe0); /* GPIO4 DIR */
114 pnp_write_register(dev, 0x38, 0x00); /* GPIO4 POL */
115 pnp_write_register(dev, 0x39, 0x80); /* GPIO4 POL */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000116
117 pnp_exit_ext_func_mode(dev);
118}
119
120static void rcba_config(void)
121{
122 /* Set up virtual channel 0 */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000123
124 /* Device 1f interrupt pin register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200125 RCBA32(D31IP) = 0x00042220;
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000126
127 /* dev irq route register */
Arthur Heymansb451df22017-08-15 20:59:09 +0200128 RCBA16(D31IR) = 0x0232;
129 RCBA16(D30IR) = 0x3246;
130 RCBA16(D29IR) = 0x0237;
131 RCBA16(D28IR) = 0x3201;
132 RCBA16(D27IR) = 0x3216;
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000133
134 /* Enable IOAPIC */
Arthur Heymansb451df22017-08-15 20:59:09 +0200135 RCBA8(OIC) = 0x03;
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000136
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000137 /* Disable unused devices */
Arthur Heymansb451df22017-08-15 20:59:09 +0200138 RCBA32(FD) = FD_PCIE6 | FD_PCIE5 | FD_PCIE3 | FD_PCIE2 |
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000139 FD_INTLAN | FD_ACMOD | FD_HDAUD | FD_PATA;
Arthur Heymansb451df22017-08-15 20:59:09 +0200140 RCBA32(FD) |= (1 << 0); /* Required. */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000141
142 /* This should probably go into the ACPI OS Init trap */
143
144 /* Set up I/O Trap #0 for 0xfe00 (SMIC) */
145 RCBA32(0x1e84) = 0x00020001;
146 RCBA32(0x1e80) = 0x0000fe01;
147
148 /* Set up I/O Trap #3 for 0x800-0x80c (Trap) */
149 RCBA32(0x1e9c) = 0x000200f0;
150 RCBA32(0x1e98) = 0x000c0801;
151}
152
153static void early_ich7_init(void)
154{
155 uint8_t reg8;
156 uint32_t reg32;
157
Elyes HAOUASec16e932016-10-07 18:22:44 +0200158 /* program secondary mlt XXX byte? */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000159 pci_write_config8(PCI_DEV(0, 0x1e, 0), 0x1b, 0x20);
160
Elyes HAOUASec16e932016-10-07 18:22:44 +0200161 /* reset rtc power status */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000162 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa4);
163 reg8 &= ~(1 << 2);
164 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa4, reg8);
165
Elyes HAOUASec16e932016-10-07 18:22:44 +0200166 /* usb transient disconnect */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000167 reg8 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xad);
168 reg8 |= (3 << 0);
169 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xad, reg8);
170
171 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xfc);
172 reg32 |= (1 << 29) | (1 << 17);
173 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xfc, reg32);
174
175 reg32 = pci_read_config32(PCI_DEV(0, 0x1d, 7), 0xdc);
176 reg32 |= (1 << 31) | (1 << 27);
177 pci_write_config32(PCI_DEV(0, 0x1d, 7), 0xdc, reg32);
178
179 RCBA32(0x0088) = 0x0011d000;
180 RCBA16(0x01fc) = 0x060f;
181 RCBA32(0x01f4) = 0x86000040;
182 RCBA32(0x0214) = 0x10030549;
183 RCBA32(0x0218) = 0x00020504;
184 RCBA8(0x0220) = 0xc5;
Arthur Heymansb451df22017-08-15 20:59:09 +0200185 reg32 = RCBA32(GCS);
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000186 reg32 |= (1 << 6);
Arthur Heymansb451df22017-08-15 20:59:09 +0200187 RCBA32(GCS) = reg32;
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000188 reg32 = RCBA32(0x3430);
189 reg32 &= ~(3 << 0);
190 reg32 |= (1 << 0);
191 RCBA32(0x3430) = reg32;
Arthur Heymansb451df22017-08-15 20:59:09 +0200192 RCBA32(FD) |= (1 << 0);
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000193 RCBA16(0x0200) = 0x2008;
194 RCBA8(0x2027) = 0x0d;
195 RCBA16(0x3e08) |= (1 << 7);
196 RCBA16(0x3e48) |= (1 << 7);
197 RCBA32(0x3e0e) |= (1 << 7);
198 RCBA32(0x3e4e) |= (1 << 7);
199
Elyes HAOUASec16e932016-10-07 18:22:44 +0200200 /* next step only on ich7m b0 and later: */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000201 reg32 = RCBA32(0x2034);
202 reg32 &= ~(0x0f << 16);
203 reg32 |= (5 << 16);
204 RCBA32(0x2034) = reg32;
205}
206
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000207static void init_artec_dongle(void)
208{
Elyes HAOUASec16e932016-10-07 18:22:44 +0200209 /* Enable 4MB decoding */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000210 outb(0xf1, 0x88);
211 outb(0xf4, 0x88);
212}
213
Kyösti Mälkki15fa9922016-06-17 10:00:28 +0300214void mainboard_romstage_entry(unsigned long bist)
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000215{
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200216 int s3resume = 0;
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000217
Paul Menzel6c20b652016-12-29 22:54:02 +0100218
219 timestamp_init(get_initial_timestamp());
220 timestamp_add_now(TS_START_ROMSTAGE);
221
Uwe Hermann7b997052010-11-21 22:47:22 +0000222 if (bist == 0)
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000223 enable_lapic();
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000224
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000225 /* Force PCIRST# */
226 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, SBR);
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000227 udelay(200 * 1000);
228 pci_write_config16(PCI_DEV(0, 0x1e, 0), BCTRL, 0);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000229
Stefan Reinauerbc8613e2010-08-25 18:35:42 +0000230 ich7_enable_lpc();
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000231 early_superio_config();
232
233 /* Set up the console */
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000234 console_init();
235
236 /* Halt if there was a built in self test failure */
237 report_bist_failure(bist);
238
239 if (MCHBAR16(SSKPD) == 0xCAFE) {
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000240 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
241 outb(0x6, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100242 halt();
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000243 }
244
245 /* Perform some early chipset initialization required
246 * before RAM initialization can work
247 */
248 i945_early_initialization();
249
250 /* This has to happen after i945_early_initialization() */
251 init_artec_dongle();
252
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200253 s3resume = southbridge_detect_s3_resume();
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000254
255 /* Enable SPD ROMs and DDR-II DRAM */
256 enable_smbus();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000257
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000258#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
259 dump_spd_registers();
260#endif
261
Paul Menzel6c20b652016-12-29 22:54:02 +0100262 timestamp_add_now(TS_BEFORE_INITRAM);
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200263 sdram_initialize(s3resume ? 2 : 0, NULL);
Paul Menzel6c20b652016-12-29 22:54:02 +0100264 timestamp_add_now(TS_AFTER_INITRAM);
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000265
266 /* Perform some initialization that must run before stage2 */
267 early_ich7_init();
268
Stefan Reinauer14e22772010-04-27 06:56:47 +0000269 /* This should probably go away. Until now it is required
270 * and mainboard specific
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000271 */
272 rcba_config();
273
274 /* Chipset Errata! */
275 fixup_i945_errata();
276
277 /* Initialize the internal PCIe links before we go into stage2 */
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200278 i945_late_initialization(s3resume);
Stefan Reinauer838c5a52010-01-17 14:08:17 +0000279}