blob: aaa17e503b187a9c4c9878d9d1665203c4ba1097 [file] [log] [blame]
Stefan Reinauer278534d2008-10-29 04:51:07 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauerbf264e92010-05-14 19:09:20 +00004 * Copyright (C) 2007-2010 coresystems GmbH
Stefan Reinauer278534d2008-10-29 04:51:07 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauer278534d2008-10-29 04:51:07 +000018 */
19
Patrick Georgid0835952010-10-05 09:07:10 +000020#include <stdint.h>
21#include <stdlib.h>
22#include <console/console.h>
23#include <arch/io.h>
Patrick Georgid0835952010-10-05 09:07:10 +000024#include <device/pci_def.h>
Vladimir Serbinenko55601882014-10-15 20:17:51 +020025#include <cbmem.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010026#include <halt.h>
Vladimir Serbinenko55601882014-10-15 20:17:51 +020027#include <string.h>
Stefan Reinauer278534d2008-10-29 04:51:07 +000028#include "i945.h"
Stefan Reinauer278534d2008-10-29 04:51:07 +000029
Patrick Georgid0835952010-10-05 09:07:10 +000030int i945_silicon_revision(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +000031{
Stefan Reinauer779b3e32008-11-10 15:43:37 +000032 return pci_read_config8(PCI_DEV(0, 0x00, 0), PCI_CLASS_REVISION);
Stefan Reinauer278534d2008-10-29 04:51:07 +000033}
34
Stefan Reinauer71a3d962009-07-21 21:44:24 +000035static void i945m_detect_chipset(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +000036{
37 u8 reg8;
38
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000039 printk(BIOS_INFO, "\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000040 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) & 0x70) >> 4;
41 switch (reg8) {
42 case 1:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000043 printk(BIOS_INFO, "Mobile Intel(R) 82945GM/GME Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000044 break;
45 case 2:
Stefan Reinauer7981b942011-04-01 22:33:25 +020046 printk(BIOS_INFO, "Mobile Intel(R) 82945GMS/GU/GSE Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000047 break;
48 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000049 printk(BIOS_INFO, "Mobile Intel(R) 82945PM Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000050 break;
51 case 5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000052 printk(BIOS_INFO, "Intel(R) 82945GT Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000053 break;
54 case 6:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000055 printk(BIOS_INFO, "Mobile Intel(R) 82943/82940GML Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000056 break;
57 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000058 printk(BIOS_INFO, "Unknown (%02x)", reg8); /* Others reserved. */
Stefan Reinauer278534d2008-10-29 04:51:07 +000059 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000060 printk(BIOS_INFO, " Chipset\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000061
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000062 printk(BIOS_DEBUG, "(G)MCH capable of up to FSB ");
Stefan Reinauer278534d2008-10-29 04:51:07 +000063 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe3) & 0xe0) >> 5;
64 switch (reg8) {
65 case 2:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000066 printk(BIOS_DEBUG, "800 MHz"); /* According to 965 spec */
Stefan Reinauer278534d2008-10-29 04:51:07 +000067 break;
68 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000069 printk(BIOS_DEBUG, "667 MHz");
Stefan Reinauer278534d2008-10-29 04:51:07 +000070 break;
71 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000072 printk(BIOS_DEBUG, "533 MHz");
Stefan Reinauer278534d2008-10-29 04:51:07 +000073 break;
74 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000075 printk(BIOS_DEBUG, "N/A MHz (%02x)", reg8);
Stefan Reinauer278534d2008-10-29 04:51:07 +000076 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000077 printk(BIOS_DEBUG, "\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000078
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000079 printk(BIOS_DEBUG, "(G)MCH capable of ");
Stefan Reinauer278534d2008-10-29 04:51:07 +000080 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
81 switch (reg8) {
82 case 2:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000083 printk(BIOS_DEBUG, "up to DDR2-667");
Stefan Reinauer278534d2008-10-29 04:51:07 +000084 break;
85 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000086 printk(BIOS_DEBUG, "up to DDR2-533");
Stefan Reinauer278534d2008-10-29 04:51:07 +000087 break;
88 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000089 printk(BIOS_DEBUG, "DDR2-400");
Stefan Reinauer278534d2008-10-29 04:51:07 +000090 break;
91 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000092 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
Stefan Reinauer278534d2008-10-29 04:51:07 +000093 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000094 printk(BIOS_DEBUG, "\n");
Kyösti Mälkkieb5e28f2012-02-24 16:08:18 +020095#if CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GC
Stefan Reinauer7981b942011-04-01 22:33:25 +020096 printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
97#endif
Stefan Reinauer278534d2008-10-29 04:51:07 +000098}
99
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000100static void i945_detect_chipset(void)
101{
102 u8 reg8;
103
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000104 printk(BIOS_INFO, "\nIntel(R) ");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000105
106 reg8 = ((pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) >> 5) & 4) | ((pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) >> 4) & 3);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000107 switch (reg8) {
108 case 0:
109 case 1:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000110 printk(BIOS_INFO, "82945G");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000111 break;
112 case 2:
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000113 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000114 printk(BIOS_INFO, "82945P");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000115 break;
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000116 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000117 printk(BIOS_INFO, "82945GC");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000118 break;
119 case 5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000120 printk(BIOS_INFO, "82945GZ");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000121 break;
122 case 6:
123 case 7:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000124 printk(BIOS_INFO, "82945PL");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000125 break;
126 default:
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000127 break;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000128 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000129 printk(BIOS_INFO, " Chipset\n");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000130
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000131 printk(BIOS_DEBUG, "(G)MCH capable of ");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000132 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
133 switch (reg8) {
134 case 0:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000135 printk(BIOS_DEBUG, "up to DDR2-667");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000136 break;
137 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000138 printk(BIOS_DEBUG, "up to DDR2-533");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000139 break;
140 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000141 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000142 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000143 printk(BIOS_DEBUG, "\n");
Kyösti Mälkkieb5e28f2012-02-24 16:08:18 +0200144#if CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GM
Stefan Reinauer7981b942011-04-01 22:33:25 +0200145 printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
146#endif
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000147}
148
Stefan Reinauer278534d2008-10-29 04:51:07 +0000149static void i945_setup_bars(void)
150{
151 u8 reg8;
152
153 /* As of now, we don't have all the A0 workarounds implemented */
154 if (i945_silicon_revision() == 0)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000155 printk(BIOS_INFO, "Warning: i945 silicon revision A0 might not work correctly.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000156
157 /* Setting up Southbridge. In the northbridge code. */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000158 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000159 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1);
160
161 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
162 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
163
164 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
165 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); /* Enable GPIOs */
166 setup_ich7_gpios();
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000167 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000168
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000169 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000170 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000171 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000172 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000173
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000174 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000175 /* Set up all hardcoded northbridge BARs */
176 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
177 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000178 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1);
179 pci_write_config32(PCI_DEV(0, 0x00, 0), X60BAR, DEFAULT_X60BAR | 1);
180
181 /* Hardware default is 8MB UMA. If someone wants to make this a
182 * CMOS or compile time option, send a patch.
183 * pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, 0x30);
184 */
185
186 /* Set C0000-FFFFF to access RAM on both reads and writes */
187 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
188 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
189 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
190 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
191 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
192 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
193 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
194
Sven Schnelled8c68a92011-06-15 09:26:34 +0200195 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, SKPAD_NORMAL_BOOT_MAGIC);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000196 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000197
198 /* Wait for MCH BAR to come up */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000199 printk(BIOS_DEBUG, "Waiting for MCHBAR to come up...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000200 if ((pci_read_config8(PCI_DEV(0, 0x0f, 0), 0xe6) & 0x2) == 0x00) { /* Bit 49 of CAPID0 */
201 do {
202 reg8 = *(volatile u8 *)0xfed40000;
203 } while (!(reg8 & 0x80));
204 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000205 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000206}
207
208static void i945_setup_egress_port(void)
209{
210 u32 reg32;
211 u32 timeout;
212
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000213 printk(BIOS_DEBUG, "Setting up Egress Port RCRB\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000214
215 /* Egress Port Virtual Channel 0 Configuration */
216
217 /* map only TC0 to VC0 */
218 reg32 = EPBAR32(EPVC0RCTL);
219 reg32 &= 0xffffff01;
220 EPBAR32(EPVC0RCTL) = reg32;
221
Stefan Reinauer278534d2008-10-29 04:51:07 +0000222 reg32 = EPBAR32(EPPVCCAP1);
223 reg32 &= ~(7 << 0);
224 reg32 |= 1;
225 EPBAR32(EPPVCCAP1) = reg32;
226
227 /* Egress Port Virtual Channel 1 Configuration */
228 reg32 = EPBAR32(0x2c);
229 reg32 &= 0xffffff00;
230 if ((MCHBAR32(CLKCFG) & 7) == 1)
231 reg32 |= 0x0d; /* 533MHz */
232 if ((MCHBAR32(CLKCFG) & 7) == 3)
233 reg32 |= 0x10; /* 667MHz */
234 EPBAR32(0x2c) = reg32;
235
236 EPBAR32(EPVC1MTS) = 0x0a0a0a0a;
237
238 reg32 = EPBAR32(EPVC1RCAP);
239 reg32 &= ~(0x7f << 16);
240 reg32 |= (0x0a << 16);
241 EPBAR32(EPVC1RCAP) = reg32;
242
243 if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */
244 EPBAR32(EPVC1IST + 0) = 0x009c009c;
245 EPBAR32(EPVC1IST + 4) = 0x009c009c;
246 }
247
248 if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */
249 EPBAR32(EPVC1IST + 0) = 0x00c000c0;
250 EPBAR32(EPVC1IST + 4) = 0x00c000c0;
251 }
252
253 /* Is internal graphics enabled? */
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300254 if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) {
Stefan Reinauer278534d2008-10-29 04:51:07 +0000255 MCHBAR32(MMARB1) |= (1 << 17);
256 }
257
258 /* Assign Virtual Channel ID 1 to VC1 */
259 reg32 = EPBAR32(EPVC1RCTL);
260 reg32 &= ~(7 << 24);
261 reg32 |= (1 << 24);
262 EPBAR32(EPVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000263
Stefan Reinauer278534d2008-10-29 04:51:07 +0000264 reg32 = EPBAR32(EPVC1RCTL);
265 reg32 &= 0xffffff01;
266 reg32 |= (1 << 7);
267 EPBAR32(EPVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000268
Stefan Reinauer278534d2008-10-29 04:51:07 +0000269 EPBAR32(PORTARB + 0x00) = 0x01000001;
270 EPBAR32(PORTARB + 0x04) = 0x00040000;
271 EPBAR32(PORTARB + 0x08) = 0x00001000;
272 EPBAR32(PORTARB + 0x0c) = 0x00000040;
273 EPBAR32(PORTARB + 0x10) = 0x01000001;
274 EPBAR32(PORTARB + 0x14) = 0x00040000;
275 EPBAR32(PORTARB + 0x18) = 0x00001000;
276 EPBAR32(PORTARB + 0x1c) = 0x00000040;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000277
Stefan Reinauer278534d2008-10-29 04:51:07 +0000278 EPBAR32(EPVC1RCTL) |= (1 << 16);
279 EPBAR32(EPVC1RCTL) |= (1 << 16);
280
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000281 printk(BIOS_DEBUG, "Loading port arbitration table ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000282 /* Loop until bit 0 becomes 0 */
283 timeout = 0x7fffff;
284 while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) ;
285 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000286 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000287 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000288 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000289
290 /* Now enable VC1 */
291 EPBAR32(EPVC1RCTL) |= (1 << 31);
292
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000293 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000294 /* Wait for VC1 negotiation pending */
295 timeout = 0x7fff;
296 while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) ;
297 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000298 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000299 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000300 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000301
302}
303
304static void ich7_setup_dmi_rcrb(void)
305{
306 u16 reg16;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000307 u32 reg32;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000308
Stefan Reinauer278534d2008-10-29 04:51:07 +0000309 reg16 = RCBA16(LCTL);
310 reg16 &= ~(3 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000311 reg16 |= 3;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000312 RCBA16(LCTL) = reg16;
313
314 RCBA32(V0CTL) = 0x80000001;
315 RCBA32(V1CAP) = 0x03128010;
316 RCBA32(ESD) = 0x00000810;
317 RCBA32(RP1D) = 0x01000003;
318 RCBA32(RP2D) = 0x02000002;
319 RCBA32(RP3D) = 0x03000002;
320 RCBA32(RP4D) = 0x04000002;
321 RCBA32(HDD) = 0x0f000003;
322 RCBA32(RP5D) = 0x05000002;
323
324 RCBA32(RPFN) = 0x00543210;
325
Stefan Reinauer30140a52009-03-11 16:20:39 +0000326 pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
327 pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
328 pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000329
Stefan Reinauer30140a52009-03-11 16:20:39 +0000330 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
331 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
332
333 reg32 = RCBA32(V1CTL);
334 reg32 &= ~( (0x7f << 1) | (7 << 17) | (7 << 24) );
335 reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31);
336 RCBA32(V1CTL) = reg32;
337
338 RCBA32(ESD) |= (2 << 16);
339
340 RCBA32(ULD) |= (1 << 24) | (1 << 16);
341
342 RCBA32(ULBA) = DEFAULT_DMIBAR;
343
344 RCBA32(RP1D) |= (2 << 16);
345 RCBA32(RP2D) |= (2 << 16);
346 RCBA32(RP3D) |= (2 << 16);
347 RCBA32(RP4D) |= (2 << 16);
348 RCBA32(HDD) |= (2 << 16);
349 RCBA32(RP5D) |= (2 << 16);
350 RCBA32(RP6D) |= (2 << 16);
351
352 RCBA32(LCAP) |= (3 << 10);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000353}
354
355static void i945_setup_dmi_rcrb(void)
356{
357 u32 reg32;
358 u32 timeout;
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000359 int activate_aspm = 1; /* hardcode ASPM for now */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000360
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000361 printk(BIOS_DEBUG, "Setting up DMI RCRB\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000362
363 /* Virtual Channel 0 Configuration */
364 reg32 = DMIBAR32(DMIVC0RCTL0);
365 reg32 &= 0xffffff01;
366 DMIBAR32(DMIVC0RCTL0) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000367
Stefan Reinauer278534d2008-10-29 04:51:07 +0000368 reg32 = DMIBAR32(DMIPVCCAP1);
369 reg32 &= ~(7 << 0);
370 reg32 |= 1;
371 DMIBAR32(DMIPVCCAP1) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000372
Stefan Reinauer278534d2008-10-29 04:51:07 +0000373 reg32 = DMIBAR32(DMIVC1RCTL);
374 reg32 &= ~(7 << 24);
375 reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
376 DMIBAR32(DMIVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000377
Stefan Reinauer278534d2008-10-29 04:51:07 +0000378 reg32 = DMIBAR32(DMIVC1RCTL);
379 reg32 &= 0xffffff01;
380 reg32 |= (1 << 7);
381 DMIBAR32(DMIVC1RCTL) = reg32;
382
383 /* Now enable VC1 */
384 DMIBAR32(DMIVC1RCTL) |= (1 << 31);
385
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000386 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000387 /* Wait for VC1 negotiation pending */
388 timeout = 0x7ffff;
389 while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) ;
390 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000391 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000392 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000393 printk(BIOS_DEBUG, "done..\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000394#if 1
395 /* Enable Active State Power Management (ASPM) L0 state */
396
397 reg32 = DMIBAR32(DMILCAP);
398 reg32 &= ~(7 << 12);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000399 reg32 |= (2 << 12);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000400
401 reg32 &= ~(7 << 15);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000402
Stefan Reinauer30140a52009-03-11 16:20:39 +0000403 reg32 |= (2 << 15);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000404 DMIBAR32(DMILCAP) = reg32;
405
406 reg32 = DMIBAR32(DMICC);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000407 reg32 &= 0x00ffffff;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000408 reg32 &= ~(3 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000409 reg32 |= (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000410 reg32 &= ~(3 << 20);
411 reg32 |= (1 << 20);
412
Stefan Reinauer278534d2008-10-29 04:51:07 +0000413 DMIBAR32(DMICC) = reg32;
414
Stefan Reinauer30140a52009-03-11 16:20:39 +0000415 if (activate_aspm) {
Stefan Reinauer278534d2008-10-29 04:51:07 +0000416 DMIBAR32(DMILCTL) |= (3 << 0);
417 }
418#endif
419
420 /* Last but not least, some additional steps */
421 reg32 = MCHBAR32(FSBSNPCTL);
422 reg32 &= ~(0xff << 2);
423 reg32 |= (0xaa << 2);
424 MCHBAR32(FSBSNPCTL) = reg32;
425
426 DMIBAR32(0x2c) = 0x86000040;
427
428 reg32 = DMIBAR32(0x204);
429 reg32 &= ~0x3ff;
430#if 1
431 reg32 |= 0x13f; /* for x4 DMI only */
432#else
433 reg32 |= 0x1e4; /* for x2 DMI only */
434#endif
435 DMIBAR32(0x204) = reg32;
436
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300437 if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000438 printk(BIOS_DEBUG, "Internal graphics: enabled\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000439 DMIBAR32(0x200) |= (1 << 21);
440 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000441 printk(BIOS_DEBUG, "Internal graphics: disabled\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000442 DMIBAR32(0x200) &= ~(1 << 21);
443 }
444
445 reg32 = DMIBAR32(0x204);
446 reg32 &= ~((1 << 11) | (1 << 10));
447 DMIBAR32(0x204) = reg32;
448
449 reg32 = DMIBAR32(0x204);
450 reg32 &= ~(0xff << 12);
451 reg32 |= (0x0d << 12);
452 DMIBAR32(0x204) = reg32;
453
454 DMIBAR32(DMICTL1) |= (3 << 24);
455
456 reg32 = DMIBAR32(0x200);
457 reg32 &= ~(0x3 << 26);
458 reg32 |= (0x02 << 26);
459 DMIBAR32(0x200) = reg32;
460
461 DMIBAR32(DMIDRCCFG) &= ~(1 << 31);
462 DMIBAR32(DMICTL2) |= (1 << 31);
463
464 if (i945_silicon_revision() >= 3) {
465 reg32 = DMIBAR32(0xec0);
466 reg32 &= 0x0fffffff;
467 reg32 |= (2 << 28);
468 DMIBAR32(0xec0) = reg32;
469
470 reg32 = DMIBAR32(0xed4);
471 reg32 &= 0x0fffffff;
472 reg32 |= (2 << 28);
473 DMIBAR32(0xed4) = reg32;
474
475 reg32 = DMIBAR32(0xee8);
476 reg32 &= 0x0fffffff;
477 reg32 |= (2 << 28);
478 DMIBAR32(0xee8) = reg32;
479
480 reg32 = DMIBAR32(0xefc);
481 reg32 &= 0x0fffffff;
482 reg32 |= (2 << 28);
483 DMIBAR32(0xefc) = reg32;
484 }
485
486 /* wait for bit toggle to 0 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000487 printk(BIOS_DEBUG, "Waiting for DMI hardware...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000488 timeout = 0x7fffff;
489 while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) ;
490 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000491 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000492 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000493 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000494
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000495 /* Clear Error Status Bits! */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000496 DMIBAR32(0x1c4) = 0xffffffff;
497 DMIBAR32(0x1d0) = 0xffffffff;
498 DMIBAR32(0x228) = 0xffffffff;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000499
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000500 /* Program Read-Only Write-Once Registers */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000501 DMIBAR32(0x308) = DMIBAR32(0x308);
502 DMIBAR32(0x314) = DMIBAR32(0x314);
503 DMIBAR32(0x324) = DMIBAR32(0x324);
504 DMIBAR32(0x328) = DMIBAR32(0x328);
505 DMIBAR32(0x338) = DMIBAR32(0x334);
506 DMIBAR32(0x338) = DMIBAR32(0x338);
507
Patrick Georgia341a772014-09-29 19:51:21 +0200508 if (i945_silicon_revision() == 1 && (MCHBAR8(DFT_STRAP1) & (1 << 5))) {
Stefan Reinauer30140a52009-03-11 16:20:39 +0000509 if ((MCHBAR32(0x214) & 0xf) != 0x3) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000510 printk(BIOS_INFO, "DMI link requires A1 stepping workaround. Rebooting.\n");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000511 reg32 = DMIBAR32(0x224);
512 reg32 &= ~(7 << 0);
513 reg32 |= (3 << 0);
514 DMIBAR32(0x224) = reg32;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000515 outb(0x06, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100516 halt(); /* wait for reset */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000517 }
518 }
519}
520
521static void i945_setup_pci_express_x16(void)
522{
523 u32 timeout;
524 u32 reg32;
525 u16 reg16;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000526
Stefan Reinauer30140a52009-03-11 16:20:39 +0000527 u8 reg8;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000528
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000529 printk(BIOS_DEBUG, "Enabling PCI Express x16 Link\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000530
531 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
532 reg16 |= DEVEN_D1F0;
533 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
534
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300535 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x208);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000536 reg32 &= ~(1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300537 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x208, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000538
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000539 /* We have no success with querying the usual PCIe registers
540 * for link setup success on the i945. Hence we assign a temporary
541 * PCI bus 0x0a and check whether we find a device on 0:a.0
542 */
543
544 /* First we reset the secondary bus */
545 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000546 reg16 |= (1 << 6); /* SRESET */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000547 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
548 /* Read back and clear reset bit. */
549 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000550 reg16 &= ~(1 << 6); /* SRESET */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000551 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
552
553 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xba);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000554 printk(BIOS_DEBUG, "SLOTSTS: %04x\n", reg16);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000555 if (!(reg16 & 0x48)) {
556 goto disable_pciexpress_x16_link;
557 }
558 reg16 |= (1 << 4) | (1 << 0);
559 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xba, reg16);
560
561 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x00);
562 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x00);
563 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x0a);
564 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x0a);
565
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300566 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000567 reg32 &= ~(1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300568 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000569
Stefan Reinauer30140a52009-03-11 16:20:39 +0000570 MCHBAR16(UPMC1) &= ~( (1 << 5) | (1 << 0) );
571
572 /* Initialze PEG_CAP */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300573 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xa2);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000574 reg16 |= (1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300575 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xa2, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000576
577 /* Setup SLOTCAP */
578 /* TODO: These values are mainboard dependent and should
Uwe Hermann607614d2010-11-18 20:12:13 +0000579 * be set from devicetree.cb.
Stefan Reinauer30140a52009-03-11 16:20:39 +0000580 */
581 /* NOTE: SLOTCAP becomes RO after the first write! */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300582 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xb4);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000583 reg32 &= 0x0007ffff;
584
585 reg32 &= 0xfffe007f;
586
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300587 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xb4, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000588
589 /* Wait for training to succeed */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000590 printk(BIOS_DEBUG, "PCIe link training ...");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000591 timeout = 0x7ffff;
Patrick Georgid3060ed2014-08-10 15:19:45 +0200592 while ((((pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS) >> 16) & 3) != 3) && --timeout) ;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000593
594 reg32 = pci_read_config32(PCI_DEV(0x0a, 0x0, 0), 0);
595 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000596 printk(BIOS_DEBUG, " Detected PCIe device %04x:%04x\n",
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000597 reg32 & 0xffff, reg32 >> 16);
598 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000599 printk(BIOS_DEBUG, " timeout!\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000600
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000601 printk(BIOS_DEBUG, "Restrain PCIe port to x1\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000602
Patrick Georgid3060ed2014-08-10 15:19:45 +0200603 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000604 reg32 &= ~(0xf << 1);
605 reg32 |=1;
Patrick Georgid3060ed2014-08-10 15:19:45 +0200606 pci_write_config32(PCI_DEV(0, 0x01, 0), PEGSTS, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000607
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300608 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000609
610 reg16 |= (1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300611 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000612 reg16 &= ~(1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300613 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000614
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000615 printk(BIOS_DEBUG, "PCIe link training ...");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000616 timeout = 0x7ffff;
Patrick Georgid3060ed2014-08-10 15:19:45 +0200617 while ((((pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS) >> 16) & 3) != 3) && --timeout) ;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000618
619 reg32 = pci_read_config32(PCI_DEV(0xa, 0x00, 0), 0);
620 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000621 printk(BIOS_DEBUG, " Detected PCIe x1 device %04x:%04x\n",
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000622 reg32 & 0xffff, reg32 >> 16);
623 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000624 printk(BIOS_DEBUG, " timeout!\n");
625 printk(BIOS_DEBUG, "Disabling PCIe x16 port completely.\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000626 goto disable_pciexpress_x16_link;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000627 }
Stefan Reinauer30140a52009-03-11 16:20:39 +0000628 }
629
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300630 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xb2);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000631 reg16 >>= 4;
632 reg16 &= 0x3f;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000633 /* reg16 == 1 -> x1; reg16 == 16 -> x16 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000634 printk(BIOS_DEBUG, "PCIe x%d link training succeeded.\n", reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000635
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300636 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x204);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000637 reg32 &= 0xfffffc00; /* clear [9:0] */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000638 if (reg16 == 1) {
639 reg32 |= 0x32b;
640 // TODO
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300641 /* pci_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000642 } else if (reg16 == 16) {
643 reg32 |= 0x0f4;
644 // TODO
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300645 /* pci_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000646 }
647
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000648 reg32 = (pci_read_config32(PCI_DEV(0xa, 0, 0), 0x8) >> 8);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000649 printk(BIOS_DEBUG, "PCIe device class: %06x\n", reg32);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000650 if (reg32 == 0x030000) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000651 printk(BIOS_DEBUG, "PCIe device is VGA. Disabling IGD.\n");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000652 reg16 = (1 << 1);
653 pci_write_config16(PCI_DEV(0, 0x0, 0), 0x52, reg16);
654
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300655 reg32 = pci_read_config32(PCI_DEV(0, 0x0, 0), DEVEN);
656 reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1);
657 pci_write_config32(PCI_DEV(0, 0x0, 0), DEVEN, reg32);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000658
659 /* Set VGA enable bit in PCIe bridge */
660 reg16 = pci_read_config16(PCI_DEV(0, 0x1, 0), 0x3e);
661 reg16 |= (1 << 3);
662 pci_write_config16(PCI_DEV(0, 0x1, 0), 0x3e, reg16);
663 }
664
Stefan Reinauer30140a52009-03-11 16:20:39 +0000665 /* Enable GPEs */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300666 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xec);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000667 reg32 |= (1 << 2) | (1 << 1) | (1 << 0); /* PMEGPE, HPGPE, GENGPE */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300668 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000669
670 /* Virtual Channel Configuration: Only VC0 on PCIe x16 */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300671 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x114);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000672 reg32 &= 0xffffff01;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300673 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000674
675 /* Extended VC count */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300676 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x104);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000677 reg32 &= ~(7 << 0);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300678 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x104, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000679
680 /* Active State Power Management ASPM */
681
682 /* TODO */
683
684 /* Clear error bits */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300685 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x06, 0xffff);
686 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x1e, 0xffff);
687 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xaa, 0xffff);
688 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1c4, 0xffffffff);
689 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1d0, 0xffffffff);
690 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1f0, 0xffffffff);
691 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x228, 0xffffffff);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000692
693 /* Program R/WO registers */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300694 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x308);
695 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x308, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000696
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300697 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x314);
698 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x314, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000699
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300700 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x324);
701 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x324, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000702
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300703 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x328);
704 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x328, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000705
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300706 reg8 = pci_read_config8(PCI_DEV(0, 0x01, 0), 0xb4);
707 pci_write_config8(PCI_DEV(0, 0x01, 0), 0xb4, reg8);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000708
709 /* Additional PCIe graphics setup */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300710 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000711 reg32 |= (3 << 26);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300712 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000713
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300714 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000715 reg32 |= (3 << 24);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300716 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000717
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300718 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000719 reg32 |= (1 << 5);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300720 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000721
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300722 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x200);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000723 reg32 &= ~(3 << 26);
724 reg32 |= (2 << 26);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300725 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x200, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000726
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300727 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000728 if (i945_silicon_revision() >= 2) {
729 reg32 |= (1 << 12);
730 } else {
731 reg32 &= ~(1 << 12);
732 }
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300733 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000734
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300735 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xeb4);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000736 reg32 &= ~(1 << 31);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300737 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xeb4, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000738
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300739 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xfc);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000740 reg32 |= (1 << 31);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300741 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xfc, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000742
743 if (i945_silicon_revision() >= 3) {
744 static const u32 reglist[] = {
745 0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24,
746 0xf38, 0xf4c, 0xf60, 0xf74, 0xf88, 0xf9c,
747 0xfb0, 0xfc4, 0xfd8, 0xfec
748 };
749
750 int i;
751 for (i=0; i<ARRAY_SIZE(reglist); i++) {
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300752 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), reglist[i]);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000753 reg32 &= 0x0fffffff;
754 reg32 |= (2 << 28);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300755 pci_write_config32(PCI_DEV(0, 0x01, 0), reglist[i], reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000756 }
757 }
758
759 if (i945_silicon_revision() <= 2 ) {
760 /* Set voltage specific parameters */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300761 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000762 reg32 &= (0xf << 4); /* Default case 1.05V */
Patrick Georgi3cb86de2014-09-29 20:42:33 +0200763 if ((MCHBAR32(DFT_STRAP1) & (1 << 20)) == 0) { /* 1.50V */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000764 reg32 |= (7 << 4);
765 }
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300766 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000767 }
768
769 return;
770
771disable_pciexpress_x16_link:
Stefan Reinauer278534d2008-10-29 04:51:07 +0000772 /* For now we just disable the x16 link */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000773 printk(BIOS_DEBUG, "Disabling PCI Express x16 Link\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000774
775 MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0);
776
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300777 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
Stefan Reinauer779b3e32008-11-10 15:43:37 +0000778 reg16 |= (1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300779 pci_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000780
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300781 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000782 reg32 |= (1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300783 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000784
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300785 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
Stefan Reinauer779b3e32008-11-10 15:43:37 +0000786 reg16 &= ~(1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300787 pci_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000788
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000789 printk(BIOS_DEBUG, "Wait for link to enter detect state... ");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000790 timeout = 0x7fffff;
Patrick Georgid3060ed2014-08-10 15:19:45 +0200791 for (reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000792 (reg32 & 0x000f0000) && --timeout;) ;
793 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000794 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000795 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000796 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000797
798 /* Finally: Disable the PCI config header */
799 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
800 reg16 &= ~DEVEN_D1F0;
801 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
802}
803
804static void i945_setup_root_complex_topology(void)
805{
806 u32 reg32;
807
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000808 printk(BIOS_DEBUG, "Setting up Root Complex Topology\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000809 /* Egress Port Root Topology */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000810
Stefan Reinauer278534d2008-10-29 04:51:07 +0000811 reg32 = EPBAR32(EPESD);
812 reg32 &= 0xff00ffff;
813 reg32 |= (1 << 16);
814 EPBAR32(EPESD) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000815
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000816 EPBAR32(EPLE1D) |= (1 << 16) | (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000817
818 EPBAR32(EPLE1A) = DEFAULT_DMIBAR;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000819
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000820 EPBAR32(EPLE2D) |= (1 << 16) | (1 << 0);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000821
822 /* DMI Port Root Topology */
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000823
Stefan Reinauer278534d2008-10-29 04:51:07 +0000824 reg32 = DMIBAR32(DMILE1D);
825 reg32 &= 0x00ffffff;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000826
Stefan Reinauer278534d2008-10-29 04:51:07 +0000827 reg32 &= 0xff00ffff;
828 reg32 |= (2 << 16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000829
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000830 reg32 |= (1 << 0);
831 DMIBAR32(DMILE1D) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000832
833 DMIBAR32(DMILE1A) = DEFAULT_RCBA;
834
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000835 DMIBAR32(DMILE2D) |= (1 << 16) | (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000836
837 DMIBAR32(DMILE2A) = DEFAULT_EPBAR;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000838
839 /* PCI Express x16 Port Root Topology */
840 if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) {
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300841 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x158, DEFAULT_EPBAR);
842 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x150);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000843 reg32 |= (1 << 0);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300844 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000845 }
846}
847
848static void ich7_setup_root_complex_topology(void)
849{
850 RCBA32(0x104) = 0x00000802;
851 RCBA32(0x110) = 0x00000001;
852 RCBA32(0x114) = 0x00000000;
853 RCBA32(0x118) = 0x00000000;
854}
855
856static void ich7_setup_pci_express(void)
857{
Stefan Reinauer30140a52009-03-11 16:20:39 +0000858 RCBA32(CG) |= (1 << 0);
859
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000860 /* Initialize slot power limit for root ports */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000861 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000862#if 0
863 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
864 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
865#endif
Stefan Reinauer278534d2008-10-29 04:51:07 +0000866
867 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
868}
869
Patrick Georgid0835952010-10-05 09:07:10 +0000870void i945_early_initialization(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +0000871{
872 /* Print some chipset specific information */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000873 switch (pci_read_config32(PCI_DEV(0, 0x00, 0), 0)) {
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000874 case 0x27708086: /* 82945G/GZ/GC/P/PL */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000875 i945_detect_chipset();
876 break;
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000877 case 0x27a08086: /* 945GME/GSE */
878 case 0x27ac8086: /* 945GM/PM/GMS/GU/GT, 943/940GML */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000879 i945m_detect_chipset();
880 break;
881 }
Stefan Reinauer278534d2008-10-29 04:51:07 +0000882
883 /* Setup all BARs required for early PCIe and raminit */
884 i945_setup_bars();
885
886 /* Change port80 to LPC */
887 RCBA32(GCS) &= (~0x04);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000888
889 /* Just do it that way */
890 RCBA32(0x2010) |= (1 << 10);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000891}
892
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200893static void i945_prepare_resume(int s3resume)
894{
895 int cbmem_was_initted;
896
897 cbmem_was_initted = !cbmem_recovery(s3resume);
898
899 /* If there is no high memory area, we didn't boot before, so
900 * this is not a resume. In that case we just create the cbmem toc.
901 */
902 if (s3resume && cbmem_was_initted) {
903 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
904
905 /* copy 1MB - 64K to high tables ram_base to prevent memory corruption
906 * through stage 2. We could keep stuff like stack and heap in high tables
907 * memory completely, but that's a wonderful clean up task for another
908 * day.
909 */
910 if (resume_backup_memory)
911 memcpy(resume_backup_memory, (void *)CONFIG_RAMBASE,
912 HIGH_MEMORY_SAVE);
913
914 /* Magic for S3 resume */
915 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD,
916 SKPAD_ACPI_S3_MAGIC);
917 }
918}
919
920void i945_late_initialization(int s3resume)
Stefan Reinauer278534d2008-10-29 04:51:07 +0000921{
922 i945_setup_egress_port();
923
924 ich7_setup_root_complex_topology();
925
926 ich7_setup_pci_express();
927
928 ich7_setup_dmi_rcrb();
929
930 i945_setup_dmi_rcrb();
931
932 i945_setup_pci_express_x16();
933
934 i945_setup_root_complex_topology();
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200935
936#if !CONFIG_HAVE_ACPI_RESUME
937#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
938#if CONFIG_DEBUG_RAM_SETUP
939 sdram_dump_mchbar_registers();
940
941 {
942 /* This will not work if TSEG is in place! */
943 u32 tom = pci_read_config32(PCI_DEV(0, 2, 0), 0x5c);
944
945 printk(BIOS_DEBUG, "TOM: 0x%08x\n", tom);
946 ram_check(0x00000000, 0x000a0000);
947 ram_check(0x00100000, tom);
948 }
949#endif
950#endif
951#endif
952
953 MCHBAR16(SSKPD) = 0xCAFE;
954
955 i945_prepare_resume(s3resume);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000956}