blob: 24054bd987e7454c66e1241bb74952c1682726de [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>
Stefan Reinauer278534d2008-10-29 04:51:07 +000025#include "i945.h"
Stefan Reinauer278534d2008-10-29 04:51:07 +000026
Patrick Georgid0835952010-10-05 09:07:10 +000027int i945_silicon_revision(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +000028{
Stefan Reinauer779b3e32008-11-10 15:43:37 +000029 return pci_read_config8(PCI_DEV(0, 0x00, 0), PCI_CLASS_REVISION);
Stefan Reinauer278534d2008-10-29 04:51:07 +000030}
31
Stefan Reinauer71a3d962009-07-21 21:44:24 +000032static void i945m_detect_chipset(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +000033{
34 u8 reg8;
35
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000036 printk(BIOS_INFO, "\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000037 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) & 0x70) >> 4;
38 switch (reg8) {
39 case 1:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000040 printk(BIOS_INFO, "Mobile Intel(R) 82945GM/GME Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000041 break;
42 case 2:
Stefan Reinauer7981b942011-04-01 22:33:25 +020043 printk(BIOS_INFO, "Mobile Intel(R) 82945GMS/GU/GSE Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000044 break;
45 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000046 printk(BIOS_INFO, "Mobile Intel(R) 82945PM Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000047 break;
48 case 5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000049 printk(BIOS_INFO, "Intel(R) 82945GT Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000050 break;
51 case 6:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000052 printk(BIOS_INFO, "Mobile Intel(R) 82943/82940GML Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000053 break;
54 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000055 printk(BIOS_INFO, "Unknown (%02x)", reg8); /* Others reserved. */
Stefan Reinauer278534d2008-10-29 04:51:07 +000056 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000057 printk(BIOS_INFO, " Chipset\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000058
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000059 printk(BIOS_DEBUG, "(G)MCH capable of up to FSB ");
Stefan Reinauer278534d2008-10-29 04:51:07 +000060 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe3) & 0xe0) >> 5;
61 switch (reg8) {
62 case 2:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000063 printk(BIOS_DEBUG, "800 MHz"); /* According to 965 spec */
Stefan Reinauer278534d2008-10-29 04:51:07 +000064 break;
65 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000066 printk(BIOS_DEBUG, "667 MHz");
Stefan Reinauer278534d2008-10-29 04:51:07 +000067 break;
68 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000069 printk(BIOS_DEBUG, "533 MHz");
Stefan Reinauer278534d2008-10-29 04:51:07 +000070 break;
71 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000072 printk(BIOS_DEBUG, "N/A MHz (%02x)", reg8);
Stefan Reinauer278534d2008-10-29 04:51:07 +000073 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000074 printk(BIOS_DEBUG, "\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000075
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000076 printk(BIOS_DEBUG, "(G)MCH capable of ");
Stefan Reinauer278534d2008-10-29 04:51:07 +000077 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
78 switch (reg8) {
79 case 2:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000080 printk(BIOS_DEBUG, "up to DDR2-667");
Stefan Reinauer278534d2008-10-29 04:51:07 +000081 break;
82 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000083 printk(BIOS_DEBUG, "up to DDR2-533");
Stefan Reinauer278534d2008-10-29 04:51:07 +000084 break;
85 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000086 printk(BIOS_DEBUG, "DDR2-400");
Stefan Reinauer278534d2008-10-29 04:51:07 +000087 break;
88 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000089 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
Stefan Reinauer278534d2008-10-29 04:51:07 +000090 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000091 printk(BIOS_DEBUG, "\n");
Kyösti Mälkkieb5e28f2012-02-24 16:08:18 +020092#if CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GC
Stefan Reinauer7981b942011-04-01 22:33:25 +020093 printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
94#endif
Stefan Reinauer278534d2008-10-29 04:51:07 +000095}
96
Stefan Reinauer71a3d962009-07-21 21:44:24 +000097static void i945_detect_chipset(void)
98{
99 u8 reg8;
100
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000101 printk(BIOS_INFO, "\nIntel(R) ");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000102
103 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 +0000104 switch (reg8) {
105 case 0:
106 case 1:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000107 printk(BIOS_INFO, "82945G");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000108 break;
109 case 2:
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000110 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000111 printk(BIOS_INFO, "82945P");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000112 break;
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000113 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000114 printk(BIOS_INFO, "82945GC");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000115 break;
116 case 5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000117 printk(BIOS_INFO, "82945GZ");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000118 break;
119 case 6:
120 case 7:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000121 printk(BIOS_INFO, "82945PL");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000122 break;
123 default:
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000124 break;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000125 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000126 printk(BIOS_INFO, " Chipset\n");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000127
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000128 printk(BIOS_DEBUG, "(G)MCH capable of ");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000129 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
130 switch (reg8) {
131 case 0:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000132 printk(BIOS_DEBUG, "up to DDR2-667");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000133 break;
134 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000135 printk(BIOS_DEBUG, "up to DDR2-533");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000136 break;
137 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000138 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000139 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000140 printk(BIOS_DEBUG, "\n");
Kyösti Mälkkieb5e28f2012-02-24 16:08:18 +0200141#if CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GM
Stefan Reinauer7981b942011-04-01 22:33:25 +0200142 printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
143#endif
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000144}
145
Stefan Reinauer278534d2008-10-29 04:51:07 +0000146static void i945_setup_bars(void)
147{
148 u8 reg8;
149
150 /* As of now, we don't have all the A0 workarounds implemented */
151 if (i945_silicon_revision() == 0)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000152 printk(BIOS_INFO, "Warning: i945 silicon revision A0 might not work correctly.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000153
154 /* Setting up Southbridge. In the northbridge code. */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000155 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000156 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1);
157
158 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
159 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
160
161 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
162 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); /* Enable GPIOs */
163 setup_ich7_gpios();
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000164 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000165
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000166 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000167 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000168 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000169 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000170
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000171 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000172 /* Set up all hardcoded northbridge BARs */
173 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
174 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000175 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1);
176 pci_write_config32(PCI_DEV(0, 0x00, 0), X60BAR, DEFAULT_X60BAR | 1);
177
178 /* Hardware default is 8MB UMA. If someone wants to make this a
179 * CMOS or compile time option, send a patch.
180 * pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, 0x30);
181 */
182
183 /* Set C0000-FFFFF to access RAM on both reads and writes */
184 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
185 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
186 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
187 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
188 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
189 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
190 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
191
Sven Schnelled8c68a92011-06-15 09:26:34 +0200192 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, SKPAD_NORMAL_BOOT_MAGIC);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000193 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000194
195 /* Wait for MCH BAR to come up */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000196 printk(BIOS_DEBUG, "Waiting for MCHBAR to come up...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000197 if ((pci_read_config8(PCI_DEV(0, 0x0f, 0), 0xe6) & 0x2) == 0x00) { /* Bit 49 of CAPID0 */
198 do {
199 reg8 = *(volatile u8 *)0xfed40000;
200 } while (!(reg8 & 0x80));
201 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000202 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000203}
204
205static void i945_setup_egress_port(void)
206{
207 u32 reg32;
208 u32 timeout;
209
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000210 printk(BIOS_DEBUG, "Setting up Egress Port RCRB\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000211
212 /* Egress Port Virtual Channel 0 Configuration */
213
214 /* map only TC0 to VC0 */
215 reg32 = EPBAR32(EPVC0RCTL);
216 reg32 &= 0xffffff01;
217 EPBAR32(EPVC0RCTL) = reg32;
218
Stefan Reinauer278534d2008-10-29 04:51:07 +0000219 reg32 = EPBAR32(EPPVCCAP1);
220 reg32 &= ~(7 << 0);
221 reg32 |= 1;
222 EPBAR32(EPPVCCAP1) = reg32;
223
224 /* Egress Port Virtual Channel 1 Configuration */
225 reg32 = EPBAR32(0x2c);
226 reg32 &= 0xffffff00;
227 if ((MCHBAR32(CLKCFG) & 7) == 1)
228 reg32 |= 0x0d; /* 533MHz */
229 if ((MCHBAR32(CLKCFG) & 7) == 3)
230 reg32 |= 0x10; /* 667MHz */
231 EPBAR32(0x2c) = reg32;
232
233 EPBAR32(EPVC1MTS) = 0x0a0a0a0a;
234
235 reg32 = EPBAR32(EPVC1RCAP);
236 reg32 &= ~(0x7f << 16);
237 reg32 |= (0x0a << 16);
238 EPBAR32(EPVC1RCAP) = reg32;
239
240 if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */
241 EPBAR32(EPVC1IST + 0) = 0x009c009c;
242 EPBAR32(EPVC1IST + 4) = 0x009c009c;
243 }
244
245 if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */
246 EPBAR32(EPVC1IST + 0) = 0x00c000c0;
247 EPBAR32(EPVC1IST + 4) = 0x00c000c0;
248 }
249
250 /* Is internal graphics enabled? */
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300251 if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) {
Stefan Reinauer278534d2008-10-29 04:51:07 +0000252 MCHBAR32(MMARB1) |= (1 << 17);
253 }
254
255 /* Assign Virtual Channel ID 1 to VC1 */
256 reg32 = EPBAR32(EPVC1RCTL);
257 reg32 &= ~(7 << 24);
258 reg32 |= (1 << 24);
259 EPBAR32(EPVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000260
Stefan Reinauer278534d2008-10-29 04:51:07 +0000261 reg32 = EPBAR32(EPVC1RCTL);
262 reg32 &= 0xffffff01;
263 reg32 |= (1 << 7);
264 EPBAR32(EPVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000265
Stefan Reinauer278534d2008-10-29 04:51:07 +0000266 EPBAR32(PORTARB + 0x00) = 0x01000001;
267 EPBAR32(PORTARB + 0x04) = 0x00040000;
268 EPBAR32(PORTARB + 0x08) = 0x00001000;
269 EPBAR32(PORTARB + 0x0c) = 0x00000040;
270 EPBAR32(PORTARB + 0x10) = 0x01000001;
271 EPBAR32(PORTARB + 0x14) = 0x00040000;
272 EPBAR32(PORTARB + 0x18) = 0x00001000;
273 EPBAR32(PORTARB + 0x1c) = 0x00000040;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000274
Stefan Reinauer278534d2008-10-29 04:51:07 +0000275 EPBAR32(EPVC1RCTL) |= (1 << 16);
276 EPBAR32(EPVC1RCTL) |= (1 << 16);
277
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000278 printk(BIOS_DEBUG, "Loading port arbitration table ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000279 /* Loop until bit 0 becomes 0 */
280 timeout = 0x7fffff;
281 while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) ;
282 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000283 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000284 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000285 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000286
287 /* Now enable VC1 */
288 EPBAR32(EPVC1RCTL) |= (1 << 31);
289
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000290 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000291 /* Wait for VC1 negotiation pending */
292 timeout = 0x7fff;
293 while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) ;
294 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000295 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000296 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000297 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000298
299}
300
301static void ich7_setup_dmi_rcrb(void)
302{
303 u16 reg16;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000304 u32 reg32;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000305
Stefan Reinauer278534d2008-10-29 04:51:07 +0000306 reg16 = RCBA16(LCTL);
307 reg16 &= ~(3 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000308 reg16 |= 3;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000309 RCBA16(LCTL) = reg16;
310
311 RCBA32(V0CTL) = 0x80000001;
312 RCBA32(V1CAP) = 0x03128010;
313 RCBA32(ESD) = 0x00000810;
314 RCBA32(RP1D) = 0x01000003;
315 RCBA32(RP2D) = 0x02000002;
316 RCBA32(RP3D) = 0x03000002;
317 RCBA32(RP4D) = 0x04000002;
318 RCBA32(HDD) = 0x0f000003;
319 RCBA32(RP5D) = 0x05000002;
320
321 RCBA32(RPFN) = 0x00543210;
322
Stefan Reinauer30140a52009-03-11 16:20:39 +0000323 pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
324 pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
325 pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000326
Stefan Reinauer30140a52009-03-11 16:20:39 +0000327 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
328 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
329
330 reg32 = RCBA32(V1CTL);
331 reg32 &= ~( (0x7f << 1) | (7 << 17) | (7 << 24) );
332 reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31);
333 RCBA32(V1CTL) = reg32;
334
335 RCBA32(ESD) |= (2 << 16);
336
337 RCBA32(ULD) |= (1 << 24) | (1 << 16);
338
339 RCBA32(ULBA) = DEFAULT_DMIBAR;
340
341 RCBA32(RP1D) |= (2 << 16);
342 RCBA32(RP2D) |= (2 << 16);
343 RCBA32(RP3D) |= (2 << 16);
344 RCBA32(RP4D) |= (2 << 16);
345 RCBA32(HDD) |= (2 << 16);
346 RCBA32(RP5D) |= (2 << 16);
347 RCBA32(RP6D) |= (2 << 16);
348
349 RCBA32(LCAP) |= (3 << 10);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000350}
351
352static void i945_setup_dmi_rcrb(void)
353{
354 u32 reg32;
355 u32 timeout;
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000356 int activate_aspm = 1; /* hardcode ASPM for now */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000357
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000358 printk(BIOS_DEBUG, "Setting up DMI RCRB\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000359
360 /* Virtual Channel 0 Configuration */
361 reg32 = DMIBAR32(DMIVC0RCTL0);
362 reg32 &= 0xffffff01;
363 DMIBAR32(DMIVC0RCTL0) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000364
Stefan Reinauer278534d2008-10-29 04:51:07 +0000365 reg32 = DMIBAR32(DMIPVCCAP1);
366 reg32 &= ~(7 << 0);
367 reg32 |= 1;
368 DMIBAR32(DMIPVCCAP1) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000369
Stefan Reinauer278534d2008-10-29 04:51:07 +0000370 reg32 = DMIBAR32(DMIVC1RCTL);
371 reg32 &= ~(7 << 24);
372 reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
373 DMIBAR32(DMIVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000374
Stefan Reinauer278534d2008-10-29 04:51:07 +0000375 reg32 = DMIBAR32(DMIVC1RCTL);
376 reg32 &= 0xffffff01;
377 reg32 |= (1 << 7);
378 DMIBAR32(DMIVC1RCTL) = reg32;
379
380 /* Now enable VC1 */
381 DMIBAR32(DMIVC1RCTL) |= (1 << 31);
382
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000383 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000384 /* Wait for VC1 negotiation pending */
385 timeout = 0x7ffff;
386 while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) ;
387 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000388 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000389 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000390 printk(BIOS_DEBUG, "done..\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000391#if 1
392 /* Enable Active State Power Management (ASPM) L0 state */
393
394 reg32 = DMIBAR32(DMILCAP);
395 reg32 &= ~(7 << 12);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000396 reg32 |= (2 << 12);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000397
398 reg32 &= ~(7 << 15);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000399
Stefan Reinauer30140a52009-03-11 16:20:39 +0000400 reg32 |= (2 << 15);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000401 DMIBAR32(DMILCAP) = reg32;
402
403 reg32 = DMIBAR32(DMICC);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000404 reg32 &= 0x00ffffff;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000405 reg32 &= ~(3 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000406 reg32 |= (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000407 reg32 &= ~(3 << 20);
408 reg32 |= (1 << 20);
409
Stefan Reinauer278534d2008-10-29 04:51:07 +0000410 DMIBAR32(DMICC) = reg32;
411
Stefan Reinauer30140a52009-03-11 16:20:39 +0000412 if (activate_aspm) {
Stefan Reinauer278534d2008-10-29 04:51:07 +0000413 DMIBAR32(DMILCTL) |= (3 << 0);
414 }
415#endif
416
417 /* Last but not least, some additional steps */
418 reg32 = MCHBAR32(FSBSNPCTL);
419 reg32 &= ~(0xff << 2);
420 reg32 |= (0xaa << 2);
421 MCHBAR32(FSBSNPCTL) = reg32;
422
423 DMIBAR32(0x2c) = 0x86000040;
424
425 reg32 = DMIBAR32(0x204);
426 reg32 &= ~0x3ff;
427#if 1
428 reg32 |= 0x13f; /* for x4 DMI only */
429#else
430 reg32 |= 0x1e4; /* for x2 DMI only */
431#endif
432 DMIBAR32(0x204) = reg32;
433
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300434 if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000435 printk(BIOS_DEBUG, "Internal graphics: enabled\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000436 DMIBAR32(0x200) |= (1 << 21);
437 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000438 printk(BIOS_DEBUG, "Internal graphics: disabled\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000439 DMIBAR32(0x200) &= ~(1 << 21);
440 }
441
442 reg32 = DMIBAR32(0x204);
443 reg32 &= ~((1 << 11) | (1 << 10));
444 DMIBAR32(0x204) = reg32;
445
446 reg32 = DMIBAR32(0x204);
447 reg32 &= ~(0xff << 12);
448 reg32 |= (0x0d << 12);
449 DMIBAR32(0x204) = reg32;
450
451 DMIBAR32(DMICTL1) |= (3 << 24);
452
453 reg32 = DMIBAR32(0x200);
454 reg32 &= ~(0x3 << 26);
455 reg32 |= (0x02 << 26);
456 DMIBAR32(0x200) = reg32;
457
458 DMIBAR32(DMIDRCCFG) &= ~(1 << 31);
459 DMIBAR32(DMICTL2) |= (1 << 31);
460
461 if (i945_silicon_revision() >= 3) {
462 reg32 = DMIBAR32(0xec0);
463 reg32 &= 0x0fffffff;
464 reg32 |= (2 << 28);
465 DMIBAR32(0xec0) = reg32;
466
467 reg32 = DMIBAR32(0xed4);
468 reg32 &= 0x0fffffff;
469 reg32 |= (2 << 28);
470 DMIBAR32(0xed4) = reg32;
471
472 reg32 = DMIBAR32(0xee8);
473 reg32 &= 0x0fffffff;
474 reg32 |= (2 << 28);
475 DMIBAR32(0xee8) = reg32;
476
477 reg32 = DMIBAR32(0xefc);
478 reg32 &= 0x0fffffff;
479 reg32 |= (2 << 28);
480 DMIBAR32(0xefc) = reg32;
481 }
482
483 /* wait for bit toggle to 0 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000484 printk(BIOS_DEBUG, "Waiting for DMI hardware...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000485 timeout = 0x7fffff;
486 while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) ;
487 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000488 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000489 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000490 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000491
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000492 /* Clear Error Status Bits! */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000493 DMIBAR32(0x1c4) = 0xffffffff;
494 DMIBAR32(0x1d0) = 0xffffffff;
495 DMIBAR32(0x228) = 0xffffffff;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000496
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000497 /* Program Read-Only Write-Once Registers */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000498 DMIBAR32(0x308) = DMIBAR32(0x308);
499 DMIBAR32(0x314) = DMIBAR32(0x314);
500 DMIBAR32(0x324) = DMIBAR32(0x324);
501 DMIBAR32(0x328) = DMIBAR32(0x328);
502 DMIBAR32(0x338) = DMIBAR32(0x334);
503 DMIBAR32(0x338) = DMIBAR32(0x338);
504
Patrick Georgia341a772014-09-29 19:51:21 +0200505 if (i945_silicon_revision() == 1 && (MCHBAR8(DFT_STRAP1) & (1 << 5))) {
Stefan Reinauer30140a52009-03-11 16:20:39 +0000506 if ((MCHBAR32(0x214) & 0xf) != 0x3) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000507 printk(BIOS_INFO, "DMI link requires A1 stepping workaround. Rebooting.\n");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000508 reg32 = DMIBAR32(0x224);
509 reg32 &= ~(7 << 0);
510 reg32 |= (3 << 0);
511 DMIBAR32(0x224) = reg32;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000512 outb(0x06, 0xcf9);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000513 for (;;) asm("hlt"); /* wait for reset */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000514 }
515 }
516}
517
518static void i945_setup_pci_express_x16(void)
519{
520 u32 timeout;
521 u32 reg32;
522 u16 reg16;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000523
Stefan Reinauer30140a52009-03-11 16:20:39 +0000524 u8 reg8;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000525
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000526 printk(BIOS_DEBUG, "Enabling PCI Express x16 Link\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000527
528 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
529 reg16 |= DEVEN_D1F0;
530 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
531
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300532 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x208);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000533 reg32 &= ~(1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300534 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x208, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000535
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000536 /* We have no success with querying the usual PCIe registers
537 * for link setup success on the i945. Hence we assign a temporary
538 * PCI bus 0x0a and check whether we find a device on 0:a.0
539 */
540
541 /* First we reset the secondary bus */
542 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000543 reg16 |= (1 << 6); /* SRESET */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000544 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
545 /* Read back and clear reset bit. */
546 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000547 reg16 &= ~(1 << 6); /* SRESET */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000548 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
549
550 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xba);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000551 printk(BIOS_DEBUG, "SLOTSTS: %04x\n", reg16);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000552 if (!(reg16 & 0x48)) {
553 goto disable_pciexpress_x16_link;
554 }
555 reg16 |= (1 << 4) | (1 << 0);
556 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xba, reg16);
557
558 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x00);
559 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x00);
560 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x0a);
561 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x0a);
562
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300563 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000564 reg32 &= ~(1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300565 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000566
Stefan Reinauer30140a52009-03-11 16:20:39 +0000567 MCHBAR16(UPMC1) &= ~( (1 << 5) | (1 << 0) );
568
569 /* Initialze PEG_CAP */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300570 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xa2);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000571 reg16 |= (1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300572 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xa2, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000573
574 /* Setup SLOTCAP */
575 /* TODO: These values are mainboard dependent and should
Uwe Hermann607614d2010-11-18 20:12:13 +0000576 * be set from devicetree.cb.
Stefan Reinauer30140a52009-03-11 16:20:39 +0000577 */
578 /* NOTE: SLOTCAP becomes RO after the first write! */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300579 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xb4);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000580 reg32 &= 0x0007ffff;
581
582 reg32 &= 0xfffe007f;
583
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300584 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xb4, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000585
586 /* Wait for training to succeed */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000587 printk(BIOS_DEBUG, "PCIe link training ...");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000588 timeout = 0x7ffff;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300589 while ((((pci_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000590
591 reg32 = pci_read_config32(PCI_DEV(0x0a, 0x0, 0), 0);
592 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000593 printk(BIOS_DEBUG, " Detected PCIe device %04x:%04x\n",
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000594 reg32 & 0xffff, reg32 >> 16);
595 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000596 printk(BIOS_DEBUG, " timeout!\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000597
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000598 printk(BIOS_DEBUG, "Restrain PCIe port to x1\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000599
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300600 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000601 reg32 &= ~(0xf << 1);
602 reg32 |=1;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300603 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x214, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000604
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300605 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000606
607 reg16 |= (1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300608 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000609 reg16 &= ~(1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300610 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000611
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000612 printk(BIOS_DEBUG, "PCIe link training ...");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000613 timeout = 0x7ffff;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300614 while ((((pci_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000615
616 reg32 = pci_read_config32(PCI_DEV(0xa, 0x00, 0), 0);
617 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000618 printk(BIOS_DEBUG, " Detected PCIe x1 device %04x:%04x\n",
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000619 reg32 & 0xffff, reg32 >> 16);
620 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000621 printk(BIOS_DEBUG, " timeout!\n");
622 printk(BIOS_DEBUG, "Disabling PCIe x16 port completely.\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000623 goto disable_pciexpress_x16_link;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000624 }
Stefan Reinauer30140a52009-03-11 16:20:39 +0000625 }
626
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300627 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xb2);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000628 reg16 >>= 4;
629 reg16 &= 0x3f;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000630 /* reg16 == 1 -> x1; reg16 == 16 -> x16 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000631 printk(BIOS_DEBUG, "PCIe x%d link training succeeded.\n", reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000632
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300633 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x204);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000634 reg32 &= 0xfffffc00; /* clear [9:0] */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000635 if (reg16 == 1) {
636 reg32 |= 0x32b;
637 // TODO
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300638 /* pci_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000639 } else if (reg16 == 16) {
640 reg32 |= 0x0f4;
641 // TODO
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300642 /* pci_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000643 }
644
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000645 reg32 = (pci_read_config32(PCI_DEV(0xa, 0, 0), 0x8) >> 8);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000646 printk(BIOS_DEBUG, "PCIe device class: %06x\n", reg32);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000647 if (reg32 == 0x030000) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000648 printk(BIOS_DEBUG, "PCIe device is VGA. Disabling IGD.\n");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000649 reg16 = (1 << 1);
650 pci_write_config16(PCI_DEV(0, 0x0, 0), 0x52, reg16);
651
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300652 reg32 = pci_read_config32(PCI_DEV(0, 0x0, 0), DEVEN);
653 reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1);
654 pci_write_config32(PCI_DEV(0, 0x0, 0), DEVEN, reg32);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000655
656 /* Set VGA enable bit in PCIe bridge */
657 reg16 = pci_read_config16(PCI_DEV(0, 0x1, 0), 0x3e);
658 reg16 |= (1 << 3);
659 pci_write_config16(PCI_DEV(0, 0x1, 0), 0x3e, reg16);
660 }
661
Stefan Reinauer30140a52009-03-11 16:20:39 +0000662 /* Enable GPEs */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300663 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xec);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000664 reg32 |= (1 << 2) | (1 << 1) | (1 << 0); /* PMEGPE, HPGPE, GENGPE */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300665 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000666
667 /* Virtual Channel Configuration: Only VC0 on PCIe x16 */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300668 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x114);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000669 reg32 &= 0xffffff01;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300670 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000671
672 /* Extended VC count */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300673 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x104);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000674 reg32 &= ~(7 << 0);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300675 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x104, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000676
677 /* Active State Power Management ASPM */
678
679 /* TODO */
680
681 /* Clear error bits */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300682 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x06, 0xffff);
683 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x1e, 0xffff);
684 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xaa, 0xffff);
685 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1c4, 0xffffffff);
686 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1d0, 0xffffffff);
687 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1f0, 0xffffffff);
688 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x228, 0xffffffff);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000689
690 /* Program R/WO registers */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300691 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x308);
692 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x308, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000693
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300694 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x314);
695 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x314, 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), 0x324);
698 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x324, 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), 0x328);
701 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x328, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000702
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300703 reg8 = pci_read_config8(PCI_DEV(0, 0x01, 0), 0xb4);
704 pci_write_config8(PCI_DEV(0, 0x01, 0), 0xb4, reg8);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000705
706 /* Additional PCIe graphics setup */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300707 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000708 reg32 |= (3 << 26);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300709 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000710
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300711 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000712 reg32 |= (3 << 24);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300713 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000714
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300715 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000716 reg32 |= (1 << 5);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300717 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000718
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300719 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x200);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000720 reg32 &= ~(3 << 26);
721 reg32 |= (2 << 26);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300722 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x200, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000723
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300724 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000725 if (i945_silicon_revision() >= 2) {
726 reg32 |= (1 << 12);
727 } else {
728 reg32 &= ~(1 << 12);
729 }
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300730 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000731
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300732 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xeb4);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000733 reg32 &= ~(1 << 31);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300734 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xeb4, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000735
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300736 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xfc);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000737 reg32 |= (1 << 31);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300738 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xfc, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000739
740 if (i945_silicon_revision() >= 3) {
741 static const u32 reglist[] = {
742 0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24,
743 0xf38, 0xf4c, 0xf60, 0xf74, 0xf88, 0xf9c,
744 0xfb0, 0xfc4, 0xfd8, 0xfec
745 };
746
747 int i;
748 for (i=0; i<ARRAY_SIZE(reglist); i++) {
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300749 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), reglist[i]);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000750 reg32 &= 0x0fffffff;
751 reg32 |= (2 << 28);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300752 pci_write_config32(PCI_DEV(0, 0x01, 0), reglist[i], reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000753 }
754 }
755
756 if (i945_silicon_revision() <= 2 ) {
757 /* Set voltage specific parameters */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300758 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000759 reg32 &= (0xf << 4); /* Default case 1.05V */
Patrick Georgi3cb86de2014-09-29 20:42:33 +0200760 if ((MCHBAR32(DFT_STRAP1) & (1 << 20)) == 0) { /* 1.50V */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000761 reg32 |= (7 << 4);
762 }
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300763 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000764 }
765
766 return;
767
768disable_pciexpress_x16_link:
Stefan Reinauer278534d2008-10-29 04:51:07 +0000769 /* For now we just disable the x16 link */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000770 printk(BIOS_DEBUG, "Disabling PCI Express x16 Link\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000771
772 MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0);
773
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300774 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
Stefan Reinauer779b3e32008-11-10 15:43:37 +0000775 reg16 |= (1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300776 pci_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000777
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300778 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000779 reg32 |= (1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300780 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000781
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300782 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
Stefan Reinauer779b3e32008-11-10 15:43:37 +0000783 reg16 &= ~(1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300784 pci_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000785
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000786 printk(BIOS_DEBUG, "Wait for link to enter detect state... ");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000787 timeout = 0x7fffff;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300788 for (reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000789 (reg32 & 0x000f0000) && --timeout;) ;
790 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000791 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000792 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000793 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000794
795 /* Finally: Disable the PCI config header */
796 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
797 reg16 &= ~DEVEN_D1F0;
798 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
799}
800
801static void i945_setup_root_complex_topology(void)
802{
803 u32 reg32;
804
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000805 printk(BIOS_DEBUG, "Setting up Root Complex Topology\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000806 /* Egress Port Root Topology */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000807
Stefan Reinauer278534d2008-10-29 04:51:07 +0000808 reg32 = EPBAR32(EPESD);
809 reg32 &= 0xff00ffff;
810 reg32 |= (1 << 16);
811 EPBAR32(EPESD) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000812
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000813 EPBAR32(EPLE1D) |= (1 << 16) | (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000814
815 EPBAR32(EPLE1A) = DEFAULT_DMIBAR;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000816
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000817 EPBAR32(EPLE2D) |= (1 << 16) | (1 << 0);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000818
819 /* DMI Port Root Topology */
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000820
Stefan Reinauer278534d2008-10-29 04:51:07 +0000821 reg32 = DMIBAR32(DMILE1D);
822 reg32 &= 0x00ffffff;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000823
Stefan Reinauer278534d2008-10-29 04:51:07 +0000824 reg32 &= 0xff00ffff;
825 reg32 |= (2 << 16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000826
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000827 reg32 |= (1 << 0);
828 DMIBAR32(DMILE1D) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000829
830 DMIBAR32(DMILE1A) = DEFAULT_RCBA;
831
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000832 DMIBAR32(DMILE2D) |= (1 << 16) | (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000833
834 DMIBAR32(DMILE2A) = DEFAULT_EPBAR;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000835
836 /* PCI Express x16 Port Root Topology */
837 if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) {
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300838 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x158, DEFAULT_EPBAR);
839 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x150);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000840 reg32 |= (1 << 0);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300841 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000842 }
843}
844
845static void ich7_setup_root_complex_topology(void)
846{
847 RCBA32(0x104) = 0x00000802;
848 RCBA32(0x110) = 0x00000001;
849 RCBA32(0x114) = 0x00000000;
850 RCBA32(0x118) = 0x00000000;
851}
852
853static void ich7_setup_pci_express(void)
854{
Stefan Reinauer30140a52009-03-11 16:20:39 +0000855 RCBA32(CG) |= (1 << 0);
856
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000857 /* Initialize slot power limit for root ports */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000858 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000859#if 0
860 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
861 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
862#endif
Stefan Reinauer278534d2008-10-29 04:51:07 +0000863
864 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
865}
866
Patrick Georgid0835952010-10-05 09:07:10 +0000867void i945_early_initialization(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +0000868{
869 /* Print some chipset specific information */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000870 switch (pci_read_config32(PCI_DEV(0, 0x00, 0), 0)) {
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000871 case 0x27708086: /* 82945G/GZ/GC/P/PL */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000872 i945_detect_chipset();
873 break;
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000874 case 0x27a08086: /* 945GME/GSE */
875 case 0x27ac8086: /* 945GM/PM/GMS/GU/GT, 943/940GML */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000876 i945m_detect_chipset();
877 break;
878 }
Stefan Reinauer278534d2008-10-29 04:51:07 +0000879
880 /* Setup all BARs required for early PCIe and raminit */
881 i945_setup_bars();
882
883 /* Change port80 to LPC */
884 RCBA32(GCS) &= (~0x04);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000885
886 /* Just do it that way */
887 RCBA32(0x2010) |= (1 << 10);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000888}
889
Patrick Georgid0835952010-10-05 09:07:10 +0000890void i945_late_initialization(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +0000891{
892 i945_setup_egress_port();
893
894 ich7_setup_root_complex_topology();
895
896 ich7_setup_pci_express();
897
898 ich7_setup_dmi_rcrb();
899
900 i945_setup_dmi_rcrb();
901
902 i945_setup_pci_express_x16();
903
904 i945_setup_root_complex_topology();
905}