blob: 43731676932dfc8a91f53b235d6ffbd670690789 [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.
Stefan Reinauer278534d2008-10-29 04:51:07 +000014 */
15
Patrick Georgid0835952010-10-05 09:07:10 +000016#include <stdint.h>
17#include <stdlib.h>
18#include <console/console.h>
Kyösti Mälkkia969ed32016-06-15 06:08:15 +030019#include <arch/acpi.h>
Patrick Georgid0835952010-10-05 09:07:10 +000020#include <arch/io.h>
Patrick Georgid0835952010-10-05 09:07:10 +000021#include <device/pci_def.h>
Vladimir Serbinenko55601882014-10-15 20:17:51 +020022#include <cbmem.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010023#include <halt.h>
Vladimir Serbinenko55601882014-10-15 20:17:51 +020024#include <string.h>
Stefan Reinauer278534d2008-10-29 04:51:07 +000025#include "i945.h"
Arthur Heymans874a8f92016-05-19 16:06:09 +020026#include <pc80/mc146818rtc.h>
Stefan Reinauer278534d2008-10-29 04:51:07 +000027
Patrick Georgid0835952010-10-05 09:07:10 +000028int i945_silicon_revision(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +000029{
Stefan Reinauer779b3e32008-11-10 15:43:37 +000030 return pci_read_config8(PCI_DEV(0, 0x00, 0), PCI_CLASS_REVISION);
Stefan Reinauer278534d2008-10-29 04:51:07 +000031}
32
Stefan Reinauer71a3d962009-07-21 21:44:24 +000033static void i945m_detect_chipset(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +000034{
35 u8 reg8;
36
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000037 printk(BIOS_INFO, "\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000038 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) & 0x70) >> 4;
39 switch (reg8) {
40 case 1:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000041 printk(BIOS_INFO, "Mobile Intel(R) 82945GM/GME Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000042 break;
43 case 2:
Stefan Reinauer7981b942011-04-01 22:33:25 +020044 printk(BIOS_INFO, "Mobile Intel(R) 82945GMS/GU/GSE Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000045 break;
46 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000047 printk(BIOS_INFO, "Mobile Intel(R) 82945PM Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000048 break;
49 case 5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000050 printk(BIOS_INFO, "Intel(R) 82945GT Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000051 break;
52 case 6:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000053 printk(BIOS_INFO, "Mobile Intel(R) 82943/82940GML Express");
Stefan Reinauer278534d2008-10-29 04:51:07 +000054 break;
55 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000056 printk(BIOS_INFO, "Unknown (%02x)", reg8); /* Others reserved. */
Stefan Reinauer278534d2008-10-29 04:51:07 +000057 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000058 printk(BIOS_INFO, " Chipset\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000059
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000060 printk(BIOS_DEBUG, "(G)MCH capable of up to FSB ");
Stefan Reinauer278534d2008-10-29 04:51:07 +000061 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe3) & 0xe0) >> 5;
62 switch (reg8) {
63 case 2:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000064 printk(BIOS_DEBUG, "800 MHz"); /* According to 965 spec */
Stefan Reinauer278534d2008-10-29 04:51:07 +000065 break;
66 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000067 printk(BIOS_DEBUG, "667 MHz");
Stefan Reinauer278534d2008-10-29 04:51:07 +000068 break;
69 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000070 printk(BIOS_DEBUG, "533 MHz");
Stefan Reinauer278534d2008-10-29 04:51:07 +000071 break;
72 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000073 printk(BIOS_DEBUG, "N/A MHz (%02x)", reg8);
Stefan Reinauer278534d2008-10-29 04:51:07 +000074 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000075 printk(BIOS_DEBUG, "\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +000076
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000077 printk(BIOS_DEBUG, "(G)MCH capable of ");
Stefan Reinauer278534d2008-10-29 04:51:07 +000078 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
79 switch (reg8) {
80 case 2:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000081 printk(BIOS_DEBUG, "up to DDR2-667");
Stefan Reinauer278534d2008-10-29 04:51:07 +000082 break;
83 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000084 printk(BIOS_DEBUG, "up to DDR2-533");
Stefan Reinauer278534d2008-10-29 04:51:07 +000085 break;
86 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000087 printk(BIOS_DEBUG, "DDR2-400");
Stefan Reinauer278534d2008-10-29 04:51:07 +000088 break;
89 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000090 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
Stefan Reinauer278534d2008-10-29 04:51:07 +000091 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000092 printk(BIOS_DEBUG, "\n");
Kyösti Mälkkieb5e28f2012-02-24 16:08:18 +020093#if CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GC
Stefan Reinauer7981b942011-04-01 22:33:25 +020094 printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
95#endif
Stefan Reinauer278534d2008-10-29 04:51:07 +000096}
97
Stefan Reinauer71a3d962009-07-21 21:44:24 +000098static void i945_detect_chipset(void)
99{
100 u8 reg8;
101
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000102 printk(BIOS_INFO, "\nIntel(R) ");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000103
104 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 +0000105 switch (reg8) {
106 case 0:
107 case 1:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000108 printk(BIOS_INFO, "82945G");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000109 break;
110 case 2:
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000111 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000112 printk(BIOS_INFO, "82945P");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000113 break;
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000114 case 4:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000115 printk(BIOS_INFO, "82945GC");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000116 break;
117 case 5:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000118 printk(BIOS_INFO, "82945GZ");
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000119 break;
120 case 6:
121 case 7:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000122 printk(BIOS_INFO, "82945PL");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000123 break;
124 default:
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000125 break;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000126 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000127 printk(BIOS_INFO, " Chipset\n");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000128
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000129 printk(BIOS_DEBUG, "(G)MCH capable of ");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000130 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
131 switch (reg8) {
132 case 0:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000133 printk(BIOS_DEBUG, "up to DDR2-667");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000134 break;
135 case 3:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000136 printk(BIOS_DEBUG, "up to DDR2-533");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000137 break;
138 default:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000139 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000140 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000141 printk(BIOS_DEBUG, "\n");
Kyösti Mälkkieb5e28f2012-02-24 16:08:18 +0200142#if CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GM
Stefan Reinauer7981b942011-04-01 22:33:25 +0200143 printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
144#endif
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000145}
146
Stefan Reinauer278534d2008-10-29 04:51:07 +0000147static void i945_setup_bars(void)
148{
Arthur Heymans874a8f92016-05-19 16:06:09 +0200149 u8 reg8, gfxsize;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000150
151 /* As of now, we don't have all the A0 workarounds implemented */
152 if (i945_silicon_revision() == 0)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000153 printk(BIOS_INFO, "Warning: i945 silicon revision A0 might not work correctly.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000154
155 /* Setting up Southbridge. In the northbridge code. */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000156 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800157 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, (uintptr_t)DEFAULT_RCBA | 1);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000158
159 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
160 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
161
162 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
163 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); /* Enable GPIOs */
164 setup_ich7_gpios();
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000165 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000166
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000167 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000168 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000169 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000170 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000171
Vladimir Serbinenko4aad7432014-11-22 20:36:58 +0100172 /* Enable upper 128bytes of CMOS */
173 RCBA32(0x3400) = (1 << 2);
174
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000175 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000176 /* Set up all hardcoded northbridge BARs */
177 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800178 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1);
179 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000180 pci_write_config32(PCI_DEV(0, 0x00, 0), X60BAR, DEFAULT_X60BAR | 1);
181
Arthur Heymans874a8f92016-05-19 16:06:09 +0200182 /* vram size from cmos option */
183 if (get_option(&gfxsize, "gfx_uma_size") != CB_SUCCESS)
184 gfxsize = 2; /* 2 for 8MB */
185 /* make sure no invalid setting is used */
186 if (gfxsize > 6)
187 gfxsize = 2;
188 pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, ((gfxsize + 1) << 4));
Stefan Reinauer278534d2008-10-29 04:51:07 +0000189
190 /* Set C0000-FFFFF to access RAM on both reads and writes */
191 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
192 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
193 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
194 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
195 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
196 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
197 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
198
Sven Schnelled8c68a92011-06-15 09:26:34 +0200199 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, SKPAD_NORMAL_BOOT_MAGIC);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000200 printk(BIOS_DEBUG, " done.\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000201
202 /* Wait for MCH BAR to come up */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000203 printk(BIOS_DEBUG, "Waiting for MCHBAR to come up...");
Elyes HAOUASa3ea1e42014-11-27 13:23:32 +0100204 if ((pci_read_config32(PCI_DEV(0, 0x00, 0), 0xe4) & 0x20000) == 0x00) { /* Bit 49 of CAPID0 */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000205 do {
206 reg8 = *(volatile u8 *)0xfed40000;
207 } while (!(reg8 & 0x80));
208 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000209 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000210}
211
212static void i945_setup_egress_port(void)
213{
214 u32 reg32;
215 u32 timeout;
216
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000217 printk(BIOS_DEBUG, "Setting up Egress Port RCRB\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000218
219 /* Egress Port Virtual Channel 0 Configuration */
220
221 /* map only TC0 to VC0 */
222 reg32 = EPBAR32(EPVC0RCTL);
223 reg32 &= 0xffffff01;
224 EPBAR32(EPVC0RCTL) = reg32;
225
Stefan Reinauer278534d2008-10-29 04:51:07 +0000226 reg32 = EPBAR32(EPPVCCAP1);
227 reg32 &= ~(7 << 0);
228 reg32 |= 1;
229 EPBAR32(EPPVCCAP1) = reg32;
230
231 /* Egress Port Virtual Channel 1 Configuration */
232 reg32 = EPBAR32(0x2c);
233 reg32 &= 0xffffff00;
234 if ((MCHBAR32(CLKCFG) & 7) == 1)
235 reg32 |= 0x0d; /* 533MHz */
236 if ((MCHBAR32(CLKCFG) & 7) == 3)
237 reg32 |= 0x10; /* 667MHz */
238 EPBAR32(0x2c) = reg32;
239
240 EPBAR32(EPVC1MTS) = 0x0a0a0a0a;
241
242 reg32 = EPBAR32(EPVC1RCAP);
243 reg32 &= ~(0x7f << 16);
244 reg32 |= (0x0a << 16);
245 EPBAR32(EPVC1RCAP) = reg32;
246
247 if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */
248 EPBAR32(EPVC1IST + 0) = 0x009c009c;
249 EPBAR32(EPVC1IST + 4) = 0x009c009c;
250 }
251
252 if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */
253 EPBAR32(EPVC1IST + 0) = 0x00c000c0;
254 EPBAR32(EPVC1IST + 4) = 0x00c000c0;
255 }
256
257 /* Is internal graphics enabled? */
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300258 if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) {
Stefan Reinauer278534d2008-10-29 04:51:07 +0000259 MCHBAR32(MMARB1) |= (1 << 17);
260 }
261
262 /* Assign Virtual Channel ID 1 to VC1 */
263 reg32 = EPBAR32(EPVC1RCTL);
264 reg32 &= ~(7 << 24);
265 reg32 |= (1 << 24);
266 EPBAR32(EPVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000267
Stefan Reinauer278534d2008-10-29 04:51:07 +0000268 reg32 = EPBAR32(EPVC1RCTL);
269 reg32 &= 0xffffff01;
270 reg32 |= (1 << 7);
271 EPBAR32(EPVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000272
Stefan Reinauer278534d2008-10-29 04:51:07 +0000273 EPBAR32(PORTARB + 0x00) = 0x01000001;
274 EPBAR32(PORTARB + 0x04) = 0x00040000;
275 EPBAR32(PORTARB + 0x08) = 0x00001000;
276 EPBAR32(PORTARB + 0x0c) = 0x00000040;
277 EPBAR32(PORTARB + 0x10) = 0x01000001;
278 EPBAR32(PORTARB + 0x14) = 0x00040000;
279 EPBAR32(PORTARB + 0x18) = 0x00001000;
280 EPBAR32(PORTARB + 0x1c) = 0x00000040;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000281
Stefan Reinauer278534d2008-10-29 04:51:07 +0000282 EPBAR32(EPVC1RCTL) |= (1 << 16);
283 EPBAR32(EPVC1RCTL) |= (1 << 16);
284
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000285 printk(BIOS_DEBUG, "Loading port arbitration table ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000286 /* Loop until bit 0 becomes 0 */
287 timeout = 0x7fffff;
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200288 while ((EPBAR16(EPVC1RSTS) & 1) && --timeout);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000289 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000290 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000291 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000292 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000293
294 /* Now enable VC1 */
295 EPBAR32(EPVC1RCTL) |= (1 << 31);
296
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000297 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000298 /* Wait for VC1 negotiation pending */
299 timeout = 0x7fff;
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200300 while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000301 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000302 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000303 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000304 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000305
306}
307
308static void ich7_setup_dmi_rcrb(void)
309{
310 u16 reg16;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000311 u32 reg32;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000312
Stefan Reinauer278534d2008-10-29 04:51:07 +0000313 reg16 = RCBA16(LCTL);
314 reg16 &= ~(3 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000315 reg16 |= 3;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000316 RCBA16(LCTL) = reg16;
317
318 RCBA32(V0CTL) = 0x80000001;
319 RCBA32(V1CAP) = 0x03128010;
320 RCBA32(ESD) = 0x00000810;
321 RCBA32(RP1D) = 0x01000003;
322 RCBA32(RP2D) = 0x02000002;
323 RCBA32(RP3D) = 0x03000002;
324 RCBA32(RP4D) = 0x04000002;
325 RCBA32(HDD) = 0x0f000003;
326 RCBA32(RP5D) = 0x05000002;
327
328 RCBA32(RPFN) = 0x00543210;
329
Stefan Reinauer30140a52009-03-11 16:20:39 +0000330 pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
331 pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
332 pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000333
Stefan Reinauer30140a52009-03-11 16:20:39 +0000334 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
335 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
336
337 reg32 = RCBA32(V1CTL);
338 reg32 &= ~( (0x7f << 1) | (7 << 17) | (7 << 24) );
339 reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31);
340 RCBA32(V1CTL) = reg32;
341
342 RCBA32(ESD) |= (2 << 16);
343
344 RCBA32(ULD) |= (1 << 24) | (1 << 16);
345
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800346 RCBA32(ULBA) = (uintptr_t)DEFAULT_DMIBAR;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000347
348 RCBA32(RP1D) |= (2 << 16);
349 RCBA32(RP2D) |= (2 << 16);
350 RCBA32(RP3D) |= (2 << 16);
351 RCBA32(RP4D) |= (2 << 16);
352 RCBA32(HDD) |= (2 << 16);
353 RCBA32(RP5D) |= (2 << 16);
354 RCBA32(RP6D) |= (2 << 16);
355
356 RCBA32(LCAP) |= (3 << 10);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000357}
358
359static void i945_setup_dmi_rcrb(void)
360{
361 u32 reg32;
362 u32 timeout;
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000363 int activate_aspm = 1; /* hardcode ASPM for now */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000364
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000365 printk(BIOS_DEBUG, "Setting up DMI RCRB\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000366
367 /* Virtual Channel 0 Configuration */
368 reg32 = DMIBAR32(DMIVC0RCTL0);
369 reg32 &= 0xffffff01;
370 DMIBAR32(DMIVC0RCTL0) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000371
Stefan Reinauer278534d2008-10-29 04:51:07 +0000372 reg32 = DMIBAR32(DMIPVCCAP1);
373 reg32 &= ~(7 << 0);
374 reg32 |= 1;
375 DMIBAR32(DMIPVCCAP1) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000376
Stefan Reinauer278534d2008-10-29 04:51:07 +0000377 reg32 = DMIBAR32(DMIVC1RCTL);
378 reg32 &= ~(7 << 24);
379 reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
380 DMIBAR32(DMIVC1RCTL) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000381
Stefan Reinauer278534d2008-10-29 04:51:07 +0000382 reg32 = DMIBAR32(DMIVC1RCTL);
383 reg32 &= 0xffffff01;
384 reg32 |= (1 << 7);
385 DMIBAR32(DMIVC1RCTL) = reg32;
386
387 /* Now enable VC1 */
388 DMIBAR32(DMIVC1RCTL) |= (1 << 31);
389
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000390 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000391 /* Wait for VC1 negotiation pending */
392 timeout = 0x7ffff;
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200393 while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000394 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000395 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000396 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000397 printk(BIOS_DEBUG, "done..\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000398#if 1
399 /* Enable Active State Power Management (ASPM) L0 state */
400
401 reg32 = DMIBAR32(DMILCAP);
402 reg32 &= ~(7 << 12);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000403 reg32 |= (2 << 12);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000404
405 reg32 &= ~(7 << 15);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000406
Stefan Reinauer30140a52009-03-11 16:20:39 +0000407 reg32 |= (2 << 15);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000408 DMIBAR32(DMILCAP) = reg32;
409
410 reg32 = DMIBAR32(DMICC);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000411 reg32 &= 0x00ffffff;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000412 reg32 &= ~(3 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000413 reg32 |= (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000414 reg32 &= ~(3 << 20);
415 reg32 |= (1 << 20);
416
Stefan Reinauer278534d2008-10-29 04:51:07 +0000417 DMIBAR32(DMICC) = reg32;
418
Stefan Reinauer30140a52009-03-11 16:20:39 +0000419 if (activate_aspm) {
Stefan Reinauer278534d2008-10-29 04:51:07 +0000420 DMIBAR32(DMILCTL) |= (3 << 0);
421 }
422#endif
423
424 /* Last but not least, some additional steps */
425 reg32 = MCHBAR32(FSBSNPCTL);
426 reg32 &= ~(0xff << 2);
427 reg32 |= (0xaa << 2);
428 MCHBAR32(FSBSNPCTL) = reg32;
429
430 DMIBAR32(0x2c) = 0x86000040;
431
432 reg32 = DMIBAR32(0x204);
433 reg32 &= ~0x3ff;
434#if 1
435 reg32 |= 0x13f; /* for x4 DMI only */
436#else
437 reg32 |= 0x1e4; /* for x2 DMI only */
438#endif
439 DMIBAR32(0x204) = reg32;
440
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300441 if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000442 printk(BIOS_DEBUG, "Internal graphics: enabled\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000443 DMIBAR32(0x200) |= (1 << 21);
444 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000445 printk(BIOS_DEBUG, "Internal graphics: disabled\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000446 DMIBAR32(0x200) &= ~(1 << 21);
447 }
448
449 reg32 = DMIBAR32(0x204);
450 reg32 &= ~((1 << 11) | (1 << 10));
451 DMIBAR32(0x204) = reg32;
452
453 reg32 = DMIBAR32(0x204);
454 reg32 &= ~(0xff << 12);
455 reg32 |= (0x0d << 12);
456 DMIBAR32(0x204) = reg32;
457
458 DMIBAR32(DMICTL1) |= (3 << 24);
459
460 reg32 = DMIBAR32(0x200);
461 reg32 &= ~(0x3 << 26);
462 reg32 |= (0x02 << 26);
463 DMIBAR32(0x200) = reg32;
464
465 DMIBAR32(DMIDRCCFG) &= ~(1 << 31);
466 DMIBAR32(DMICTL2) |= (1 << 31);
467
468 if (i945_silicon_revision() >= 3) {
469 reg32 = DMIBAR32(0xec0);
470 reg32 &= 0x0fffffff;
471 reg32 |= (2 << 28);
472 DMIBAR32(0xec0) = reg32;
473
474 reg32 = DMIBAR32(0xed4);
475 reg32 &= 0x0fffffff;
476 reg32 |= (2 << 28);
477 DMIBAR32(0xed4) = reg32;
478
479 reg32 = DMIBAR32(0xee8);
480 reg32 &= 0x0fffffff;
481 reg32 |= (2 << 28);
482 DMIBAR32(0xee8) = reg32;
483
484 reg32 = DMIBAR32(0xefc);
485 reg32 &= 0x0fffffff;
486 reg32 |= (2 << 28);
487 DMIBAR32(0xefc) = reg32;
488 }
489
490 /* wait for bit toggle to 0 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000491 printk(BIOS_DEBUG, "Waiting for DMI hardware...");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000492 timeout = 0x7fffff;
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200493 while ((DMIBAR8(0x32) & (1 << 1)) && --timeout);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000494 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000495 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000496 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000497 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000498
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000499 /* Clear Error Status Bits! */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000500 DMIBAR32(0x1c4) = 0xffffffff;
501 DMIBAR32(0x1d0) = 0xffffffff;
502 DMIBAR32(0x228) = 0xffffffff;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000503
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000504 /* Program Read-Only Write-Once Registers */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000505 DMIBAR32(0x308) = DMIBAR32(0x308);
506 DMIBAR32(0x314) = DMIBAR32(0x314);
507 DMIBAR32(0x324) = DMIBAR32(0x324);
508 DMIBAR32(0x328) = DMIBAR32(0x328);
509 DMIBAR32(0x338) = DMIBAR32(0x334);
510 DMIBAR32(0x338) = DMIBAR32(0x338);
511
Patrick Georgia341a772014-09-29 19:51:21 +0200512 if (i945_silicon_revision() == 1 && (MCHBAR8(DFT_STRAP1) & (1 << 5))) {
Stefan Reinauer30140a52009-03-11 16:20:39 +0000513 if ((MCHBAR32(0x214) & 0xf) != 0x3) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000514 printk(BIOS_INFO, "DMI link requires A1 stepping workaround. Rebooting.\n");
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000515 reg32 = DMIBAR32(0x224);
516 reg32 &= ~(7 << 0);
517 reg32 |= (3 << 0);
518 DMIBAR32(0x224) = reg32;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000519 outb(0x06, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100520 halt(); /* wait for reset */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000521 }
522 }
523}
524
525static void i945_setup_pci_express_x16(void)
526{
527 u32 timeout;
528 u32 reg32;
529 u16 reg16;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000530
Stefan Reinauer30140a52009-03-11 16:20:39 +0000531 u8 reg8;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000532
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000533 printk(BIOS_DEBUG, "Enabling PCI Express x16 Link\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000534
535 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
536 reg16 |= DEVEN_D1F0;
537 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
538
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300539 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x208);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000540 reg32 &= ~(1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300541 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x208, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000542
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000543 /* We have no success with querying the usual PCIe registers
544 * for link setup success on the i945. Hence we assign a temporary
545 * PCI bus 0x0a and check whether we find a device on 0:a.0
546 */
547
548 /* First we reset the secondary bus */
549 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000550 reg16 |= (1 << 6); /* SRESET */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000551 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
552 /* Read back and clear reset bit. */
553 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000554 reg16 &= ~(1 << 6); /* SRESET */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000555 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
556
557 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xba);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000558 printk(BIOS_DEBUG, "SLOTSTS: %04x\n", reg16);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000559 if (!(reg16 & 0x48)) {
560 goto disable_pciexpress_x16_link;
561 }
562 reg16 |= (1 << 4) | (1 << 0);
563 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xba, reg16);
564
565 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x00);
566 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x00);
567 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x0a);
568 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x0a);
569
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300570 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000571 reg32 &= ~(1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300572 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000573
Stefan Reinauer30140a52009-03-11 16:20:39 +0000574 MCHBAR16(UPMC1) &= ~( (1 << 5) | (1 << 0) );
575
576 /* Initialze PEG_CAP */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300577 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xa2);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000578 reg16 |= (1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300579 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xa2, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000580
581 /* Setup SLOTCAP */
582 /* TODO: These values are mainboard dependent and should
Uwe Hermann607614d2010-11-18 20:12:13 +0000583 * be set from devicetree.cb.
Stefan Reinauer30140a52009-03-11 16:20:39 +0000584 */
585 /* NOTE: SLOTCAP becomes RO after the first write! */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300586 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xb4);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000587 reg32 &= 0x0007ffff;
588
589 reg32 &= 0xfffe007f;
590
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300591 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xb4, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000592
593 /* Wait for training to succeed */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000594 printk(BIOS_DEBUG, "PCIe link training ...");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000595 timeout = 0x7ffff;
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200596 while ((((pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS) >> 16) & 3) != 3) && --timeout);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000597
598 reg32 = pci_read_config32(PCI_DEV(0x0a, 0x0, 0), 0);
599 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000600 printk(BIOS_DEBUG, " Detected PCIe device %04x:%04x\n",
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000601 reg32 & 0xffff, reg32 >> 16);
602 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000603 printk(BIOS_DEBUG, " timeout!\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000604
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000605 printk(BIOS_DEBUG, "Restrain PCIe port to x1\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000606
Patrick Georgid3060ed2014-08-10 15:19:45 +0200607 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000608 reg32 &= ~(0xf << 1);
609 reg32 |=1;
Patrick Georgid3060ed2014-08-10 15:19:45 +0200610 pci_write_config32(PCI_DEV(0, 0x01, 0), PEGSTS, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000611
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300612 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000613
614 reg16 |= (1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300615 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000616 reg16 &= ~(1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300617 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000618
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000619 printk(BIOS_DEBUG, "PCIe link training ...");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000620 timeout = 0x7ffff;
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200621 while ((((pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS) >> 16) & 3) != 3) && --timeout);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000622
623 reg32 = pci_read_config32(PCI_DEV(0xa, 0x00, 0), 0);
624 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000625 printk(BIOS_DEBUG, " Detected PCIe x1 device %04x:%04x\n",
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000626 reg32 & 0xffff, reg32 >> 16);
627 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000628 printk(BIOS_DEBUG, " timeout!\n");
629 printk(BIOS_DEBUG, "Disabling PCIe x16 port completely.\n");
Stefan Reinauer30140a52009-03-11 16:20:39 +0000630 goto disable_pciexpress_x16_link;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000631 }
Stefan Reinauer30140a52009-03-11 16:20:39 +0000632 }
633
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300634 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xb2);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000635 reg16 >>= 4;
636 reg16 &= 0x3f;
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000637 /* reg16 == 1 -> x1; reg16 == 16 -> x16 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000638 printk(BIOS_DEBUG, "PCIe x%d link training succeeded.\n", reg16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000639
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300640 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x204);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000641 reg32 &= 0xfffffc00; /* clear [9:0] */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000642 if (reg16 == 1) {
643 reg32 |= 0x32b;
644 // TODO
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300645 /* pci_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000646 } else if (reg16 == 16) {
647 reg32 |= 0x0f4;
648 // TODO
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300649 /* pci_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000650 }
651
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000652 reg32 = (pci_read_config32(PCI_DEV(0xa, 0, 0), 0x8) >> 8);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000653 printk(BIOS_DEBUG, "PCIe device class: %06x\n", reg32);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000654 if (reg32 == 0x030000) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000655 printk(BIOS_DEBUG, "PCIe device is VGA. Disabling IGD.\n");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000656 reg16 = (1 << 1);
657 pci_write_config16(PCI_DEV(0, 0x0, 0), 0x52, reg16);
658
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +0300659 reg32 = pci_read_config32(PCI_DEV(0, 0x0, 0), DEVEN);
660 reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1);
661 pci_write_config32(PCI_DEV(0, 0x0, 0), DEVEN, reg32);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000662
663 /* Set VGA enable bit in PCIe bridge */
664 reg16 = pci_read_config16(PCI_DEV(0, 0x1, 0), 0x3e);
665 reg16 |= (1 << 3);
666 pci_write_config16(PCI_DEV(0, 0x1, 0), 0x3e, reg16);
667 }
668
Stefan Reinauer30140a52009-03-11 16:20:39 +0000669 /* Enable GPEs */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300670 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xec);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000671 reg32 |= (1 << 2) | (1 << 1) | (1 << 0); /* PMEGPE, HPGPE, GENGPE */
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 /* Virtual Channel Configuration: Only VC0 on PCIe x16 */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300675 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x114);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000676 reg32 &= 0xffffff01;
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300677 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000678
679 /* Extended VC count */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300680 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x104);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000681 reg32 &= ~(7 << 0);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300682 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x104, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000683
684 /* Active State Power Management ASPM */
685
686 /* TODO */
687
688 /* Clear error bits */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300689 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x06, 0xffff);
690 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x1e, 0xffff);
691 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xaa, 0xffff);
692 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1c4, 0xffffffff);
693 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1d0, 0xffffffff);
694 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1f0, 0xffffffff);
695 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x228, 0xffffffff);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000696
697 /* Program R/WO registers */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300698 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x308);
699 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x308, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000700
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300701 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x314);
702 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x314, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000703
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300704 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x324);
705 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x324, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000706
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300707 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x328);
708 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x328, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000709
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300710 reg8 = pci_read_config8(PCI_DEV(0, 0x01, 0), 0xb4);
711 pci_write_config8(PCI_DEV(0, 0x01, 0), 0xb4, reg8);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000712
713 /* Additional PCIe graphics setup */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300714 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000715 reg32 |= (3 << 26);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300716 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000717
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300718 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000719 reg32 |= (3 << 24);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300720 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000721
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300722 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000723 reg32 |= (1 << 5);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300724 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000725
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300726 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x200);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000727 reg32 &= ~(3 << 26);
728 reg32 |= (2 << 26);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300729 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x200, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000730
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300731 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000732 if (i945_silicon_revision() >= 2) {
733 reg32 |= (1 << 12);
734 } else {
735 reg32 &= ~(1 << 12);
736 }
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300737 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000738
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300739 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xeb4);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000740 reg32 &= ~(1 << 31);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300741 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xeb4, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000742
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300743 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xfc);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000744 reg32 |= (1 << 31);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300745 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xfc, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000746
747 if (i945_silicon_revision() >= 3) {
748 static const u32 reglist[] = {
749 0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24,
750 0xf38, 0xf4c, 0xf60, 0xf74, 0xf88, 0xf9c,
751 0xfb0, 0xfc4, 0xfd8, 0xfec
752 };
753
754 int i;
Elyes HAOUAS0a15fe92016-09-17 19:12:27 +0200755 for (i = 0; i < ARRAY_SIZE(reglist); i++) {
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300756 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), reglist[i]);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000757 reg32 &= 0x0fffffff;
758 reg32 |= (2 << 28);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300759 pci_write_config32(PCI_DEV(0, 0x01, 0), reglist[i], reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000760 }
761 }
762
763 if (i945_silicon_revision() <= 2 ) {
764 /* Set voltage specific parameters */
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300765 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000766 reg32 &= (0xf << 4); /* Default case 1.05V */
Patrick Georgi3cb86de2014-09-29 20:42:33 +0200767 if ((MCHBAR32(DFT_STRAP1) & (1 << 20)) == 0) { /* 1.50V */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000768 reg32 |= (7 << 4);
769 }
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300770 pci_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000771 }
772
773 return;
774
775disable_pciexpress_x16_link:
Stefan Reinauer278534d2008-10-29 04:51:07 +0000776 /* For now we just disable the x16 link */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000777 printk(BIOS_DEBUG, "Disabling PCI Express x16 Link\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000778
779 MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0);
780
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300781 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
Stefan Reinauer779b3e32008-11-10 15:43:37 +0000782 reg16 |= (1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300783 pci_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000784
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300785 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000786 reg32 |= (1 << 8);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300787 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000788
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300789 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
Stefan Reinauer779b3e32008-11-10 15:43:37 +0000790 reg16 &= ~(1 << 6);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300791 pci_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000792
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000793 printk(BIOS_DEBUG, "Wait for link to enter detect state... ");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000794 timeout = 0x7fffff;
Patrick Georgid3060ed2014-08-10 15:19:45 +0200795 for (reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS);
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200796 (reg32 & 0x000f0000) && --timeout;);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000797 if (!timeout)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000798 printk(BIOS_DEBUG, "timeout!\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000799 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000800 printk(BIOS_DEBUG, "ok\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000801
802 /* Finally: Disable the PCI config header */
803 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
804 reg16 &= ~DEVEN_D1F0;
805 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
806}
807
808static void i945_setup_root_complex_topology(void)
809{
810 u32 reg32;
811
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000812 printk(BIOS_DEBUG, "Setting up Root Complex Topology\n");
Stefan Reinauer278534d2008-10-29 04:51:07 +0000813 /* Egress Port Root Topology */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000814
Stefan Reinauer278534d2008-10-29 04:51:07 +0000815 reg32 = EPBAR32(EPESD);
816 reg32 &= 0xff00ffff;
817 reg32 |= (1 << 16);
818 EPBAR32(EPESD) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000819
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000820 EPBAR32(EPLE1D) |= (1 << 16) | (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000821
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800822 EPBAR32(EPLE1A) = (uintptr_t)DEFAULT_DMIBAR;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000823
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000824 EPBAR32(EPLE2D) |= (1 << 16) | (1 << 0);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000825
826 /* DMI Port Root Topology */
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000827
Stefan Reinauer278534d2008-10-29 04:51:07 +0000828 reg32 = DMIBAR32(DMILE1D);
829 reg32 &= 0x00ffffff;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000830
Stefan Reinauer278534d2008-10-29 04:51:07 +0000831 reg32 &= 0xff00ffff;
832 reg32 |= (2 << 16);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000833
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000834 reg32 |= (1 << 0);
835 DMIBAR32(DMILE1D) = reg32;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000836
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800837 DMIBAR32(DMILE1A) = (uintptr_t)DEFAULT_RCBA;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000838
Stefan Reinauer24b4df52010-01-17 13:47:35 +0000839 DMIBAR32(DMILE2D) |= (1 << 16) | (1 << 0);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000840
841 DMIBAR32(DMILE2A) = DEFAULT_EPBAR;
Stefan Reinauer278534d2008-10-29 04:51:07 +0000842
843 /* PCI Express x16 Port Root Topology */
844 if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) {
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300845 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x158, DEFAULT_EPBAR);
846 reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x150);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000847 reg32 |= (1 << 0);
Kyösti Mälkki8aa7e832013-07-26 08:52:10 +0300848 pci_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000849 }
850}
851
852static void ich7_setup_root_complex_topology(void)
853{
854 RCBA32(0x104) = 0x00000802;
855 RCBA32(0x110) = 0x00000001;
856 RCBA32(0x114) = 0x00000000;
857 RCBA32(0x118) = 0x00000000;
858}
859
860static void ich7_setup_pci_express(void)
861{
Stefan Reinauer30140a52009-03-11 16:20:39 +0000862 RCBA32(CG) |= (1 << 0);
863
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000864 /* Initialize slot power limit for root ports */
Stefan Reinauer278534d2008-10-29 04:51:07 +0000865 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000866#if 0
867 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
868 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
869#endif
Stefan Reinauer278534d2008-10-29 04:51:07 +0000870
871 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
872}
873
Patrick Georgid0835952010-10-05 09:07:10 +0000874void i945_early_initialization(void)
Stefan Reinauer278534d2008-10-29 04:51:07 +0000875{
876 /* Print some chipset specific information */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000877 switch (pci_read_config32(PCI_DEV(0, 0x00, 0), 0)) {
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000878 case 0x27708086: /* 82945G/GZ/GC/P/PL */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000879 i945_detect_chipset();
880 break;
Stefan Reinauerbf264e92010-05-14 19:09:20 +0000881 case 0x27a08086: /* 945GME/GSE */
882 case 0x27ac8086: /* 945GM/PM/GMS/GU/GT, 943/940GML */
Stefan Reinauer71a3d962009-07-21 21:44:24 +0000883 i945m_detect_chipset();
884 break;
885 }
Stefan Reinauer278534d2008-10-29 04:51:07 +0000886
887 /* Setup all BARs required for early PCIe and raminit */
888 i945_setup_bars();
889
890 /* Change port80 to LPC */
891 RCBA32(GCS) &= (~0x04);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000892
893 /* Just do it that way */
894 RCBA32(0x2010) |= (1 << 10);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000895}
896
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200897static void i945_prepare_resume(int s3resume)
898{
899 int cbmem_was_initted;
900
901 cbmem_was_initted = !cbmem_recovery(s3resume);
902
903 /* If there is no high memory area, we didn't boot before, so
904 * this is not a resume. In that case we just create the cbmem toc.
905 */
906 if (s3resume && cbmem_was_initted) {
Kyösti Mälkkie6b5a4f2016-06-17 22:52:04 +0300907 acpi_prepare_for_resume();
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200908
909 /* Magic for S3 resume */
910 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD,
911 SKPAD_ACPI_S3_MAGIC);
912 }
913}
914
915void i945_late_initialization(int s3resume)
Stefan Reinauer278534d2008-10-29 04:51:07 +0000916{
917 i945_setup_egress_port();
918
919 ich7_setup_root_complex_topology();
920
921 ich7_setup_pci_express();
922
923 ich7_setup_dmi_rcrb();
924
925 i945_setup_dmi_rcrb();
926
927 i945_setup_pci_express_x16();
928
929 i945_setup_root_complex_topology();
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200930
931#if !CONFIG_HAVE_ACPI_RESUME
932#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8
933#if CONFIG_DEBUG_RAM_SETUP
934 sdram_dump_mchbar_registers();
935
936 {
937 /* This will not work if TSEG is in place! */
Paul Menzel9d3e1312014-06-05 08:50:17 +0200938 u32 tom = pci_read_config32(PCI_DEV(0, 2, 0), BSM);
Vladimir Serbinenko55601882014-10-15 20:17:51 +0200939
940 printk(BIOS_DEBUG, "TOM: 0x%08x\n", tom);
941 ram_check(0x00000000, 0x000a0000);
942 ram_check(0x00100000, tom);
943 }
944#endif
945#endif
946#endif
947
948 MCHBAR16(SSKPD) = 0xCAFE;
949
950 i945_prepare_resume(s3resume);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000951}