blob: 1715c476adc0f5cd949d643a05a2399737172a29 [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>
26#include <string.h>
Stefan Reinauer278534d2008-10-29 04:51:07 +000027#include "i945.h"
Stefan Reinauer278534d2008-10-29 04:51:07 +000028
Patrick Georgid0835952010-10-05 09:07:10 +000029int i945_silicon_revision(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +000030{
Stefan Reinauer779b3e32008-11-10 15:43:37 +000031 return pci_read_config8(PCI_DEV(0, 0x00, 0), PCI_CLASS_REVISION);
Stefan Reinauer278534d2008-10-29 04:51:07 +000032}
33
Stefan Reinauer71a3d962009-07-21 21:44:24 +000034static void i945m_detect_chipset(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +000035{
36 u8 reg8;
37
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000038 printk(BIOS_INFO, "\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000039 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) & 0x70) >> 4;
40 switch (reg8) {
41 case 1:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000042 printk(BIOS_INFO, "Mobile Intel(R) 82945GM/GME Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000043 break;
44 case 2:
Stefan Reinauer7981b942011-04-01 22:33:25 +020045 printk(BIOS_INFO, "Mobile Intel(R) 82945GMS/GU/GSE Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000046 break;
47 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000048 printk(BIOS_INFO, "Mobile Intel(R) 82945PM Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000049 break;
50 case 5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000051 printk(BIOS_INFO, "Intel(R) 82945GT Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000052 break;
53 case 6:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000054 printk(BIOS_INFO, "Mobile Intel(R) 82943/82940GML Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000055 break;
56 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000057 printk(BIOS_INFO, "Unknown (%02x)", reg8); /* Others reserved. */
Stefan Reinauer278534d2008-10-29 04:51:07 +000058 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000059 printk(BIOS_INFO, " Chipset\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000060
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000061 printk(BIOS_DEBUG, "(G)MCH capable of up to FSB ");
Stefan Reinauer278534d2008-10-29 04:51:07 +000062 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe3) & 0xe0) >> 5;
63 switch (reg8) {
64 case 2:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000065 printk(BIOS_DEBUG, "800 MHz"); /* According to 965 spec */
Stefan Reinauer278534d2008-10-29 04:51:07 +000066 break;
67 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000068 printk(BIOS_DEBUG, "667 MHz");
Stefan Reinauer278534d2008-10-29 04:51:07 +000069 break;
70 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000071 printk(BIOS_DEBUG, "533 MHz");
Stefan Reinauer278534d2008-10-29 04:51:07 +000072 break;
73 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000074 printk(BIOS_DEBUG, "N/A MHz (%02x)", reg8);
Stefan Reinauer278534d2008-10-29 04:51:07 +000075 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000076 printk(BIOS_DEBUG, "\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000077
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000078 printk(BIOS_DEBUG, "(G)MCH capable of ");
Stefan Reinauer278534d2008-10-29 04:51:07 +000079 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
80 switch (reg8) {
81 case 2:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000082 printk(BIOS_DEBUG, "up to DDR2-667");
Stefan Reinauer278534d2008-10-29 04:51:07 +000083 break;
84 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000085 printk(BIOS_DEBUG, "up to DDR2-533");
Stefan Reinauer278534d2008-10-29 04:51:07 +000086 break;
87 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000088 printk(BIOS_DEBUG, "DDR2-400");
Stefan Reinauer278534d2008-10-29 04:51:07 +000089 break;
90 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000091 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
Stefan Reinauer278534d2008-10-29 04:51:07 +000092 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000093 printk(BIOS_DEBUG, "\n");
Kyösti Mälkkieb5e28f2012-02-24 16:08:18 +020094#if CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GC
Stefan Reinauer7981b942011-04-01 22:33:25 +020095 printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
96#endif
Stefan Reinauer278534d2008-10-29 04:51:07 +000097}
98
Stefan Reinauer71a3d962009-07-21 21:44:24 +000099static void i945_detect_chipset(void)
100{
101 u8 reg8;
102
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000103 printk(BIOS_INFO, "\nIntel(R) ");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000104
105 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 +0000106 switch (reg8) {
107 case 0:
108 case 1:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000109 printk(BIOS_INFO, "82945G");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000110 break;
111 case 2:
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000112 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000113 printk(BIOS_INFO, "82945P");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000114 break;
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000115 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000116 printk(BIOS_INFO, "82945GC");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000117 break;
118 case 5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000119 printk(BIOS_INFO, "82945GZ");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000120 break;
121 case 6:
122 case 7:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000123 printk(BIOS_INFO, "82945PL");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000124 break;
125 default:
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000126 break;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000127 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000128 printk(BIOS_INFO, " Chipset\n");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000129
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000130 printk(BIOS_DEBUG, "(G)MCH capable of ");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000131 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
132 switch (reg8) {
133 case 0:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000134 printk(BIOS_DEBUG, "up to DDR2-667");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000135 break;
136 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000137 printk(BIOS_DEBUG, "up to DDR2-533");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000138 break;
139 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000140 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000141 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000142 printk(BIOS_DEBUG, "\n");
Kyösti Mälkkieb5e28f2012-02-24 16:08:18 +0200143#if CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GM
Stefan Reinauer7981b942011-04-01 22:33:25 +0200144 printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
145#endif
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000146}
147
Stefan Reinauer278534d2008-10-29 04:51:07 +0000148static void i945_setup_bars(void)
149{
150 u8 reg8;
151
152 /* As of now, we don't have all the A0 workarounds implemented */
153 if (i945_silicon_revision() == 0)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000154 printk(BIOS_INFO, "Warning: i945 silicon revision A0 might not work correctly.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000155
156 /* Setting up Southbridge. In the northbridge code. */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000157 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000158 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1);
159
160 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
161 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
162
163 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
164 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); /* Enable GPIOs */
165 setup_ich7_gpios();
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000166 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000167
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000168 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000169 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000170 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000171 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000172
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000173 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000174 /* Set up all hardcoded northbridge BARs */
175 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
176 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000177 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1);
178 pci_write_config32(PCI_DEV(0, 0x00, 0), X60BAR, DEFAULT_X60BAR | 1);
179
180 /* Hardware default is 8MB UMA. If someone wants to make this a
181 * CMOS or compile time option, send a patch.
182 * pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, 0x30);
183 */
184
185 /* Set C0000-FFFFF to access RAM on both reads and writes */
186 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
187 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
188 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
189 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
190 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
191 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
192 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
193
Sven Schnelled8c68a92011-06-15 09:26:34 +0200194 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, SKPAD_NORMAL_BOOT_MAGIC);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000195 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000196
197 /* Wait for MCH BAR to come up */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000198 printk(BIOS_DEBUG, "Waiting for MCHBAR to come up...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000199 if ((pci_read_config8(PCI_DEV(0, 0x0f, 0), 0xe6) & 0x2) == 0x00) { /* Bit 49 of CAPID0 */
200 do {
201 reg8 = *(volatile u8 *)0xfed40000;
202 } while (!(reg8 & 0x80));
203 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000204 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000205}
206
207static void i945_setup_egress_port(void)
208{
209 u32 reg32;
210 u32 timeout;
211
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000212 printk(BIOS_DEBUG, "Setting up Egress Port RCRB\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000213
214 /* Egress Port Virtual Channel 0 Configuration */
215
216 /* map only TC0 to VC0 */
217 reg32 = EPBAR32(EPVC0RCTL);
218 reg32 &= 0xffffff01;
219 EPBAR32(EPVC0RCTL) = reg32;
220
Stefan Reinauer278534d2008-10-29 04:51:07 +0000221 reg32 = EPBAR32(EPPVCCAP1);
222 reg32 &= ~(7 << 0);
223 reg32 |= 1;
224 EPBAR32(EPPVCCAP1) = reg32;
225
226 /* Egress Port Virtual Channel 1 Configuration */
227 reg32 = EPBAR32(0x2c);
228 reg32 &= 0xffffff00;
229 if ((MCHBAR32(CLKCFG) & 7) == 1)
230 reg32 |= 0x0d; /* 533MHz */
231 if ((MCHBAR32(CLKCFG) & 7) == 3)
232 reg32 |= 0x10; /* 667MHz */
233 EPBAR32(0x2c) = reg32;
234
235 EPBAR32(EPVC1MTS) = 0x0a0a0a0a;
236
237 reg32 = EPBAR32(EPVC1RCAP);
238 reg32 &= ~(0x7f << 16);
239 reg32 |= (0x0a << 16);
240 EPBAR32(EPVC1RCAP) = reg32;
241
242 if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */
243 EPBAR32(EPVC1IST + 0) = 0x009c009c;
244 EPBAR32(EPVC1IST + 4) = 0x009c009c;
245 }
246
247 if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */
248 EPBAR32(EPVC1IST + 0) = 0x00c000c0;
249 EPBAR32(EPVC1IST + 4) = 0x00c000c0;
250 }
251
252 /* Is internal graphics enabled? */
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300253 if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) {
Stefan Reinauer278534d2008-10-29 04:51:07 +0000254 MCHBAR32(MMARB1) |= (1 << 17);
255 }
256
257 /* Assign Virtual Channel ID 1 to VC1 */
258 reg32 = EPBAR32(EPVC1RCTL);
259 reg32 &= ~(7 << 24);
260 reg32 |= (1 << 24);
261 EPBAR32(EPVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000262
Stefan Reinauer278534d2008-10-29 04:51:07 +0000263 reg32 = EPBAR32(EPVC1RCTL);
264 reg32 &= 0xffffff01;
265 reg32 |= (1 << 7);
266 EPBAR32(EPVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000267
Stefan Reinauer278534d2008-10-29 04:51:07 +0000268 EPBAR32(PORTARB + 0x00) = 0x01000001;
269 EPBAR32(PORTARB + 0x04) = 0x00040000;
270 EPBAR32(PORTARB + 0x08) = 0x00001000;
271 EPBAR32(PORTARB + 0x0c) = 0x00000040;
272 EPBAR32(PORTARB + 0x10) = 0x01000001;
273 EPBAR32(PORTARB + 0x14) = 0x00040000;
274 EPBAR32(PORTARB + 0x18) = 0x00001000;
275 EPBAR32(PORTARB + 0x1c) = 0x00000040;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000276
Stefan Reinauer278534d2008-10-29 04:51:07 +0000277 EPBAR32(EPVC1RCTL) |= (1 << 16);
278 EPBAR32(EPVC1RCTL) |= (1 << 16);
279
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000280 printk(BIOS_DEBUG, "Loading port arbitration table ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000281 /* Loop until bit 0 becomes 0 */
282 timeout = 0x7fffff;
283 while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) ;
284 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000285 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000286 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000287 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000288
289 /* Now enable VC1 */
290 EPBAR32(EPVC1RCTL) |= (1 << 31);
291
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000292 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000293 /* Wait for VC1 negotiation pending */
294 timeout = 0x7fff;
295 while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) ;
296 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000297 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000298 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000299 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000300
301}
302
303static void ich7_setup_dmi_rcrb(void)
304{
305 u16 reg16;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000306 u32 reg32;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000307
Stefan Reinauer278534d2008-10-29 04:51:07 +0000308 reg16 = RCBA16(LCTL);
309 reg16 &= ~(3 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000310 reg16 |= 3;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000311 RCBA16(LCTL) = reg16;
312
313 RCBA32(V0CTL) = 0x80000001;
314 RCBA32(V1CAP) = 0x03128010;
315 RCBA32(ESD) = 0x00000810;
316 RCBA32(RP1D) = 0x01000003;
317 RCBA32(RP2D) = 0x02000002;
318 RCBA32(RP3D) = 0x03000002;
319 RCBA32(RP4D) = 0x04000002;
320 RCBA32(HDD) = 0x0f000003;
321 RCBA32(RP5D) = 0x05000002;
322
323 RCBA32(RPFN) = 0x00543210;
324
Stefan Reinauer30140a52009-03-11 16:20:39 +0000325 pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
326 pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
327 pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000328
Stefan Reinauer30140a52009-03-11 16:20:39 +0000329 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
330 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
331
332 reg32 = RCBA32(V1CTL);
333 reg32 &= ~( (0x7f << 1) | (7 << 17) | (7 << 24) );
334 reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31);
335 RCBA32(V1CTL) = reg32;
336
337 RCBA32(ESD) |= (2 << 16);
338
339 RCBA32(ULD) |= (1 << 24) | (1 << 16);
340
341 RCBA32(ULBA) = DEFAULT_DMIBAR;
342
343 RCBA32(RP1D) |= (2 << 16);
344 RCBA32(RP2D) |= (2 << 16);
345 RCBA32(RP3D) |= (2 << 16);
346 RCBA32(RP4D) |= (2 << 16);
347 RCBA32(HDD) |= (2 << 16);
348 RCBA32(RP5D) |= (2 << 16);
349 RCBA32(RP6D) |= (2 << 16);
350
351 RCBA32(LCAP) |= (3 << 10);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000352}
353
354static void i945_setup_dmi_rcrb(void)
355{
356 u32 reg32;
357 u32 timeout;
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000358 int activate_aspm = 1; /* hardcode ASPM for now */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000359
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000360 printk(BIOS_DEBUG, "Setting up DMI RCRB\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000361
362 /* Virtual Channel 0 Configuration */
363 reg32 = DMIBAR32(DMIVC0RCTL0);
364 reg32 &= 0xffffff01;
365 DMIBAR32(DMIVC0RCTL0) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000366
Stefan Reinauer278534d2008-10-29 04:51:07 +0000367 reg32 = DMIBAR32(DMIPVCCAP1);
368 reg32 &= ~(7 << 0);
369 reg32 |= 1;
370 DMIBAR32(DMIPVCCAP1) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000371
Stefan Reinauer278534d2008-10-29 04:51:07 +0000372 reg32 = DMIBAR32(DMIVC1RCTL);
373 reg32 &= ~(7 << 24);
374 reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
375 DMIBAR32(DMIVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000376
Stefan Reinauer278534d2008-10-29 04:51:07 +0000377 reg32 = DMIBAR32(DMIVC1RCTL);
378 reg32 &= 0xffffff01;
379 reg32 |= (1 << 7);
380 DMIBAR32(DMIVC1RCTL) = reg32;
381
382 /* Now enable VC1 */
383 DMIBAR32(DMIVC1RCTL) |= (1 << 31);
384
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000385 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000386 /* Wait for VC1 negotiation pending */
387 timeout = 0x7ffff;
388 while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) ;
389 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000390 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000391 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000392 printk(BIOS_DEBUG, "done..\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000393#if 1
394 /* Enable Active State Power Management (ASPM) L0 state */
395
396 reg32 = DMIBAR32(DMILCAP);
397 reg32 &= ~(7 << 12);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000398 reg32 |= (2 << 12);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000399
400 reg32 &= ~(7 << 15);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000401
Stefan Reinauer30140a52009-03-11 16:20:39 +0000402 reg32 |= (2 << 15);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000403 DMIBAR32(DMILCAP) = reg32;
404
405 reg32 = DMIBAR32(DMICC);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000406 reg32 &= 0x00ffffff;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000407 reg32 &= ~(3 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000408 reg32 |= (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000409 reg32 &= ~(3 << 20);
410 reg32 |= (1 << 20);
411
Stefan Reinauer278534d2008-10-29 04:51:07 +0000412 DMIBAR32(DMICC) = reg32;
413
Stefan Reinauer30140a52009-03-11 16:20:39 +0000414 if (activate_aspm) {
Stefan Reinauer278534d2008-10-29 04:51:07 +0000415 DMIBAR32(DMILCTL) |= (3 << 0);
416 }
417#endif
418
419 /* Last but not least, some additional steps */
420 reg32 = MCHBAR32(FSBSNPCTL);
421 reg32 &= ~(0xff << 2);
422 reg32 |= (0xaa << 2);
423 MCHBAR32(FSBSNPCTL) = reg32;
424
425 DMIBAR32(0x2c) = 0x86000040;
426
427 reg32 = DMIBAR32(0x204);
428 reg32 &= ~0x3ff;
429#if 1
430 reg32 |= 0x13f; /* for x4 DMI only */
431#else
432 reg32 |= 0x1e4; /* for x2 DMI only */
433#endif
434 DMIBAR32(0x204) = reg32;
435
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300436 if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000437 printk(BIOS_DEBUG, "Internal graphics: enabled\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000438 DMIBAR32(0x200) |= (1 << 21);
439 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000440 printk(BIOS_DEBUG, "Internal graphics: disabled\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000441 DMIBAR32(0x200) &= ~(1 << 21);
442 }
443
444 reg32 = DMIBAR32(0x204);
445 reg32 &= ~((1 << 11) | (1 << 10));
446 DMIBAR32(0x204) = reg32;
447
448 reg32 = DMIBAR32(0x204);
449 reg32 &= ~(0xff << 12);
450 reg32 |= (0x0d << 12);
451 DMIBAR32(0x204) = reg32;
452
453 DMIBAR32(DMICTL1) |= (3 << 24);
454
455 reg32 = DMIBAR32(0x200);
456 reg32 &= ~(0x3 << 26);
457 reg32 |= (0x02 << 26);
458 DMIBAR32(0x200) = reg32;
459
460 DMIBAR32(DMIDRCCFG) &= ~(1 << 31);
461 DMIBAR32(DMICTL2) |= (1 << 31);
462
463 if (i945_silicon_revision() >= 3) {
464 reg32 = DMIBAR32(0xec0);
465 reg32 &= 0x0fffffff;
466 reg32 |= (2 << 28);
467 DMIBAR32(0xec0) = reg32;
468
469 reg32 = DMIBAR32(0xed4);
470 reg32 &= 0x0fffffff;
471 reg32 |= (2 << 28);
472 DMIBAR32(0xed4) = reg32;
473
474 reg32 = DMIBAR32(0xee8);
475 reg32 &= 0x0fffffff;
476 reg32 |= (2 << 28);
477 DMIBAR32(0xee8) = reg32;
478
479 reg32 = DMIBAR32(0xefc);
480 reg32 &= 0x0fffffff;
481 reg32 |= (2 << 28);
482 DMIBAR32(0xefc) = reg32;
483 }
484
485 /* wait for bit toggle to 0 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000486 printk(BIOS_DEBUG, "Waiting for DMI hardware...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000487 timeout = 0x7fffff;
488 while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) ;
489 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000490 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000491 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000492 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000493
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000494 /* Clear Error Status Bits! */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000495 DMIBAR32(0x1c4) = 0xffffffff;
496 DMIBAR32(0x1d0) = 0xffffffff;
497 DMIBAR32(0x228) = 0xffffffff;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000498
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000499 /* Program Read-Only Write-Once Registers */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000500 DMIBAR32(0x308) = DMIBAR32(0x308);
501 DMIBAR32(0x314) = DMIBAR32(0x314);
502 DMIBAR32(0x324) = DMIBAR32(0x324);
503 DMIBAR32(0x328) = DMIBAR32(0x328);
504 DMIBAR32(0x338) = DMIBAR32(0x334);
505 DMIBAR32(0x338) = DMIBAR32(0x338);
506
Patrick Georgia341a772014-09-29 19:51:21 +0200507 if (i945_silicon_revision() == 1 && (MCHBAR8(DFT_STRAP1) & (1 << 5))) {
Stefan Reinauer30140a52009-03-11 16:20:39 +0000508 if ((MCHBAR32(0x214) & 0xf) != 0x3) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000509 printk(BIOS_INFO, "DMI link requires A1 stepping workaround. Rebooting.\n");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000510 reg32 = DMIBAR32(0x224);
511 reg32 &= ~(7 << 0);
512 reg32 |= (3 << 0);
513 DMIBAR32(0x224) = reg32;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000514 outb(0x06, 0xcf9);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000515 for (;;) asm("hlt"); /* wait for reset */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000516 }
517 }
518}
519
520static void i945_setup_pci_express_x16(void)
521{
522 u32 timeout;
523 u32 reg32;
524 u16 reg16;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000525
Stefan Reinauer30140a52009-03-11 16:20:39 +0000526 u8 reg8;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000527
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000528 printk(BIOS_DEBUG, "Enabling PCI Express x16 Link\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000529
530 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
531 reg16 |= DEVEN_D1F0;
532 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
533
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300534 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x208);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000535 reg32 &= ~(1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300536 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x208, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000537
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000538 /* We have no success with querying the usual PCIe registers
539 * for link setup success on the i945. Hence we assign a temporary
540 * PCI bus 0x0a and check whether we find a device on 0:a.0
541 */
542
543 /* First we reset the secondary bus */
544 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000545 reg16 |= (1 << 6); /* SRESET */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000546 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
547 /* Read back and clear reset bit. */
548 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000549 reg16 &= ~(1 << 6); /* SRESET */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000550 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
551
552 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xba);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000553 printk(BIOS_DEBUG, "SLOTSTS: %04x\n", reg16);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000554 if (!(reg16 & 0x48)) {
555 goto disable_pciexpress_x16_link;
556 }
557 reg16 |= (1 << 4) | (1 << 0);
558 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xba, reg16);
559
560 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x00);
561 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x00);
562 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x0a);
563 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x0a);
564
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300565 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000566 reg32 &= ~(1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300567 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000568
Stefan Reinauer30140a52009-03-11 16:20:39 +0000569 MCHBAR16(UPMC1) &= ~( (1 << 5) | (1 << 0) );
570
571 /* Initialze PEG_CAP */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300572 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xa2);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000573 reg16 |= (1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300574 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xa2, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000575
576 /* Setup SLOTCAP */
577 /* TODO: These values are mainboard dependent and should
Uwe Hermann607614d2010-11-18 20:12:13 +0000578 * be set from devicetree.cb.
Stefan Reinauer30140a52009-03-11 16:20:39 +0000579 */
580 /* NOTE: SLOTCAP becomes RO after the first write! */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300581 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xb4);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000582 reg32 &= 0x0007ffff;
583
584 reg32 &= 0xfffe007f;
585
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300586 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xb4, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000587
588 /* Wait for training to succeed */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000589 printk(BIOS_DEBUG, "PCIe link training ...");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000590 timeout = 0x7ffff;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300591 while ((((pci_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000592
593 reg32 = pci_read_config32(PCI_DEV(0x0a, 0x0, 0), 0);
594 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000595 printk(BIOS_DEBUG, " Detected PCIe device %04x:%04x\n",
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000596 reg32 & 0xffff, reg32 >> 16);
597 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000598 printk(BIOS_DEBUG, " timeout!\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000599
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000600 printk(BIOS_DEBUG, "Restrain PCIe port to x1\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000601
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300602 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000603 reg32 &= ~(0xf << 1);
604 reg32 |=1;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300605 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x214, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000606
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300607 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000608
609 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 reg16 &= ~(1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300612 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000613
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000614 printk(BIOS_DEBUG, "PCIe link training ...");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000615 timeout = 0x7ffff;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300616 while ((((pci_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000617
618 reg32 = pci_read_config32(PCI_DEV(0xa, 0x00, 0), 0);
619 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000620 printk(BIOS_DEBUG, " Detected PCIe x1 device %04x:%04x\n",
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000621 reg32 & 0xffff, reg32 >> 16);
622 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000623 printk(BIOS_DEBUG, " timeout!\n");
624 printk(BIOS_DEBUG, "Disabling PCIe x16 port completely.\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000625 goto disable_pciexpress_x16_link;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000626 }
Stefan Reinauer30140a52009-03-11 16:20:39 +0000627 }
628
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300629 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xb2);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000630 reg16 >>= 4;
631 reg16 &= 0x3f;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000632 /* reg16 == 1 -> x1; reg16 == 16 -> x16 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000633 printk(BIOS_DEBUG, "PCIe x%d link training succeeded.\n", reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000634
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300635 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x204);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000636 reg32 &= 0xfffffc00; /* clear [9:0] */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000637 if (reg16 == 1) {
638 reg32 |= 0x32b;
639 // TODO
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300640 /* pci_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000641 } else if (reg16 == 16) {
642 reg32 |= 0x0f4;
643 // TODO
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300644 /* pci_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000645 }
646
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000647 reg32 = (pci_read_config32(PCI_DEV(0xa, 0, 0), 0x8) >> 8);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000648 printk(BIOS_DEBUG, "PCIe device class: %06x\n", reg32);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000649 if (reg32 == 0x030000) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000650 printk(BIOS_DEBUG, "PCIe device is VGA. Disabling IGD.\n");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000651 reg16 = (1 << 1);
652 pci_write_config16(PCI_DEV(0, 0x0, 0), 0x52, reg16);
653
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300654 reg32 = pci_read_config32(PCI_DEV(0, 0x0, 0), DEVEN);
655 reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1);
656 pci_write_config32(PCI_DEV(0, 0x0, 0), DEVEN, reg32);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000657
658 /* Set VGA enable bit in PCIe bridge */
659 reg16 = pci_read_config16(PCI_DEV(0, 0x1, 0), 0x3e);
660 reg16 |= (1 << 3);
661 pci_write_config16(PCI_DEV(0, 0x1, 0), 0x3e, reg16);
662 }
663
Stefan Reinauer30140a52009-03-11 16:20:39 +0000664 /* Enable GPEs */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300665 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xec);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000666 reg32 |= (1 << 2) | (1 << 1) | (1 << 0); /* PMEGPE, HPGPE, GENGPE */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300667 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000668
669 /* Virtual Channel Configuration: Only VC0 on PCIe x16 */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300670 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x114);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000671 reg32 &= 0xffffff01;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300672 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000673
674 /* Extended VC count */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300675 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x104);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000676 reg32 &= ~(7 << 0);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300677 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x104, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000678
679 /* Active State Power Management ASPM */
680
681 /* TODO */
682
683 /* Clear error bits */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300684 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x06, 0xffff);
685 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x1e, 0xffff);
686 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xaa, 0xffff);
687 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1c4, 0xffffffff);
688 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1d0, 0xffffffff);
689 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1f0, 0xffffffff);
690 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x228, 0xffffffff);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000691
692 /* Program R/WO registers */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300693 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x308);
694 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x308, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000695
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300696 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x314);
697 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x314, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000698
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300699 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x324);
700 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x324, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000701
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300702 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x328);
703 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x328, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000704
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300705 reg8 = pci_read_config8(PCI_DEV(0, 0x01, 0), 0xb4);
706 pci_write_config8(PCI_DEV(0, 0x01, 0), 0xb4, reg8);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000707
708 /* Additional PCIe graphics setup */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300709 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000710 reg32 |= (3 << 26);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300711 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000712
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300713 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000714 reg32 |= (3 << 24);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300715 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000716
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300717 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000718 reg32 |= (1 << 5);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300719 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000720
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300721 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x200);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000722 reg32 &= ~(3 << 26);
723 reg32 |= (2 << 26);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300724 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x200, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000725
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300726 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000727 if (i945_silicon_revision() >= 2) {
728 reg32 |= (1 << 12);
729 } else {
730 reg32 &= ~(1 << 12);
731 }
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300732 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000733
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300734 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xeb4);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000735 reg32 &= ~(1 << 31);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300736 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xeb4, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000737
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300738 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xfc);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000739 reg32 |= (1 << 31);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300740 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xfc, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000741
742 if (i945_silicon_revision() >= 3) {
743 static const u32 reglist[] = {
744 0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24,
745 0xf38, 0xf4c, 0xf60, 0xf74, 0xf88, 0xf9c,
746 0xfb0, 0xfc4, 0xfd8, 0xfec
747 };
748
749 int i;
750 for (i=0; i<ARRAY_SIZE(reglist); i++) {
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300751 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), reglist[i]);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000752 reg32 &= 0x0fffffff;
753 reg32 |= (2 << 28);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300754 pci_write_config32(PCI_DEV(0, 0x01, 0), reglist[i], reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000755 }
756 }
757
758 if (i945_silicon_revision() <= 2 ) {
759 /* Set voltage specific parameters */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300760 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000761 reg32 &= (0xf << 4); /* Default case 1.05V */
Patrick Georgi3cb86de2014-09-29 20:42:33 +0200762 if ((MCHBAR32(DFT_STRAP1) & (1 << 20)) == 0) { /* 1.50V */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000763 reg32 |= (7 << 4);
764 }
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300765 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000766 }
767
768 return;
769
770disable_pciexpress_x16_link:
Stefan Reinauer278534d2008-10-29 04:51:07 +0000771 /* For now we just disable the x16 link */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000772 printk(BIOS_DEBUG, "Disabling PCI Express x16 Link\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000773
774 MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0);
775
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300776 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
Stefan Reinauer779b3e32008-11-10 15:43:37 +0000777 reg16 |= (1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300778 pci_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000779
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300780 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000781 reg32 |= (1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300782 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000783
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300784 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
Stefan Reinauer779b3e32008-11-10 15:43:37 +0000785 reg16 &= ~(1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300786 pci_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000787
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000788 printk(BIOS_DEBUG, "Wait for link to enter detect state... ");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000789 timeout = 0x7fffff;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300790 for (reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000791 (reg32 & 0x000f0000) && --timeout;) ;
792 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000793 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000794 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000795 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000796
797 /* Finally: Disable the PCI config header */
798 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
799 reg16 &= ~DEVEN_D1F0;
800 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
801}
802
803static void i945_setup_root_complex_topology(void)
804{
805 u32 reg32;
806
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000807 printk(BIOS_DEBUG, "Setting up Root Complex Topology\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000808 /* Egress Port Root Topology */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000809
Stefan Reinauer278534d2008-10-29 04:51:07 +0000810 reg32 = EPBAR32(EPESD);
811 reg32 &= 0xff00ffff;
812 reg32 |= (1 << 16);
813 EPBAR32(EPESD) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000814
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000815 EPBAR32(EPLE1D) |= (1 << 16) | (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000816
817 EPBAR32(EPLE1A) = DEFAULT_DMIBAR;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000818
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000819 EPBAR32(EPLE2D) |= (1 << 16) | (1 << 0);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000820
821 /* DMI Port Root Topology */
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000822
Stefan Reinauer278534d2008-10-29 04:51:07 +0000823 reg32 = DMIBAR32(DMILE1D);
824 reg32 &= 0x00ffffff;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000825
Stefan Reinauer278534d2008-10-29 04:51:07 +0000826 reg32 &= 0xff00ffff;
827 reg32 |= (2 << 16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000828
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000829 reg32 |= (1 << 0);
830 DMIBAR32(DMILE1D) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000831
832 DMIBAR32(DMILE1A) = DEFAULT_RCBA;
833
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000834 DMIBAR32(DMILE2D) |= (1 << 16) | (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000835
836 DMIBAR32(DMILE2A) = DEFAULT_EPBAR;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000837
838 /* PCI Express x16 Port Root Topology */
839 if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) {
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300840 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x158, DEFAULT_EPBAR);
841 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x150);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000842 reg32 |= (1 << 0);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300843 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000844 }
845}
846
847static void ich7_setup_root_complex_topology(void)
848{
849 RCBA32(0x104) = 0x00000802;
850 RCBA32(0x110) = 0x00000001;
851 RCBA32(0x114) = 0x00000000;
852 RCBA32(0x118) = 0x00000000;
853}
854
855static void ich7_setup_pci_express(void)
856{
Stefan Reinauer30140a52009-03-11 16:20:39 +0000857 RCBA32(CG) |= (1 << 0);
858
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000859 /* Initialize slot power limit for root ports */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000860 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000861#if 0
862 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
863 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
864#endif
Stefan Reinauer278534d2008-10-29 04:51:07 +0000865
866 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
867}
868
Patrick Georgid0835952010-10-05 09:07:10 +0000869void i945_early_initialization(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +0000870{
871 /* Print some chipset specific information */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000872 switch (pci_read_config32(PCI_DEV(0, 0x00, 0), 0)) {
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000873 case 0x27708086: /* 82945G/GZ/GC/P/PL */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000874 i945_detect_chipset();
875 break;
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000876 case 0x27a08086: /* 945GME/GSE */
877 case 0x27ac8086: /* 945GM/PM/GMS/GU/GT, 943/940GML */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000878 i945m_detect_chipset();
879 break;
880 }
Stefan Reinauer278534d2008-10-29 04:51:07 +0000881
882 /* Setup all BARs required for early PCIe and raminit */
883 i945_setup_bars();
884
885 /* Change port80 to LPC */
886 RCBA32(GCS) &= (~0x04);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000887
888 /* Just do it that way */
889 RCBA32(0x2010) |= (1 << 10);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000890}
891
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200892static void i945_prepare_resume(int s3resume)
893{
894 int cbmem_was_initted;
895
896 cbmem_was_initted = !cbmem_recovery(s3resume);
897
898 /* If there is no high memory area, we didn't boot before, so
899 * this is not a resume. In that case we just create the cbmem toc.
900 */
901 if (s3resume && cbmem_was_initted) {
902 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
903
904 /* copy 1MB - 64K to high tables ram_base to prevent memory corruption
905 * through stage 2. We could keep stuff like stack and heap in high tables
906 * memory completely, but that's a wonderful clean up task for another
907 * day.
908 */
909 if (resume_backup_memory)
910 memcpy(resume_backup_memory, (void *)CONFIG_RAMBASE,
911 HIGH_MEMORY_SAVE);
912
913 /* Magic for S3 resume */
914 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD,
915 SKPAD_ACPI_S3_MAGIC);
916 }
917}
918
919void i945_late_initialization(int s3resume)
Stefan Reinauer278534d2008-10-29 04:51:07 +0000920{
921 i945_setup_egress_port();
922
923 ich7_setup_root_complex_topology();
924
925 ich7_setup_pci_express();
926
927 ich7_setup_dmi_rcrb();
928
929 i945_setup_dmi_rcrb();
930
931 i945_setup_pci_express_x16();
932
933 i945_setup_root_complex_topology();
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200934
935#if !CONFIG_HAVE_ACPI_RESUME
936#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
937#if CONFIG_DEBUG_RAM_SETUP
938 sdram_dump_mchbar_registers();
939
940 {
941 /* This will not work if TSEG is in place! */
942 u32 tom = pci_read_config32(PCI_DEV(0, 2, 0), 0x5c);
943
944 printk(BIOS_DEBUG, "TOM: 0x%08x\n", tom);
945 ram_check(0x00000000, 0x000a0000);
946 ram_check(0x00100000, tom);
947 }
948#endif
949#endif
950#endif
951
952 MCHBAR16(SSKPD) = 0xCAFE;
953
954 i945_prepare_resume(s3resume);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000955}