2 * This file is part of the coreboot project.
4 * Copyright (C) 2007-2009 coresystems GmbH
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.
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.
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
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "pcie_config.c"
23 static int i945_silicon_revision(void)
25 return pci_read_config8(PCI_DEV(0, 0x00, 0), PCI_CLASS_REVISION);
28 static void i945m_detect_chipset(void)
32 printk(BIOS_INFO, "\n");
33 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) & 0x70) >> 4;
36 printk(BIOS_INFO, "Mobile Intel(R) 82945GM/GME Express");
39 printk(BIOS_INFO, "Mobile Intel(R) 82945GMS/GU Express");
42 printk(BIOS_INFO, "Mobile Intel(R) 82945PM Express");
45 printk(BIOS_INFO, "Intel(R) 82945GT Express");
48 printk(BIOS_INFO, "Mobile Intel(R) 82943/82940GML Express");
51 printk(BIOS_INFO, "Unknown (%02x)", reg8); /* Others reserved. */
53 printk(BIOS_INFO, " Chipset\n");
55 printk(BIOS_DEBUG, "(G)MCH capable of up to FSB ");
56 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe3) & 0xe0) >> 5;
59 printk(BIOS_DEBUG, "800 MHz"); /* According to 965 spec */
62 printk(BIOS_DEBUG, "667 MHz");
65 printk(BIOS_DEBUG, "533 MHz");
68 printk(BIOS_DEBUG, "N/A MHz (%02x)", reg8);
70 printk(BIOS_DEBUG, "\n");
72 printk(BIOS_DEBUG, "(G)MCH capable of ");
73 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
76 printk(BIOS_DEBUG, "up to DDR2-667");
79 printk(BIOS_DEBUG, "up to DDR2-533");
82 printk(BIOS_DEBUG, "DDR2-400");
85 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
87 printk(BIOS_DEBUG, "\n");
90 static void i945_detect_chipset(void)
94 printk(BIOS_INFO, "\nIntel(R) ");
96 reg8 = ((pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) >> 5) & 4) | ((pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) >> 4) & 3);
100 printk(BIOS_INFO, "82945G");
104 printk(BIOS_INFO, "82945P");
107 printk(BIOS_INFO, "82945GC");
110 printk(BIOS_INFO, "82945GZ");
114 printk(BIOS_INFO, "82945PL");
119 printk(BIOS_INFO, " Chipset\n");
121 printk(BIOS_DEBUG, "(G)MCH capable of ");
122 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
125 printk(BIOS_DEBUG, "up to DDR2-667");
128 printk(BIOS_DEBUG, "up to DDR2-533");
131 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
133 printk(BIOS_DEBUG, "\n");
136 static void i945_setup_bars(void)
140 /* As of now, we don't have all the A0 workarounds implemented */
141 if (i945_silicon_revision() == 0)
142 printk(BIOS_INFO, "Warning: i945 silicon revision A0 might not work correctly.\n");
144 /* Setting up Southbridge. In the northbridge code. */
145 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
146 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1);
148 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
149 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
151 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
152 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); /* Enable GPIOs */
154 printk(BIOS_DEBUG, " done.\n");
156 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
157 RCBA32(GCS) = (RCBA32(0x3410)) | (1 << 5); /* No reset */
158 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
159 printk(BIOS_DEBUG, " done.\n");
161 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
162 /* Set up all hardcoded northbridge BARs */
163 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
164 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
165 pci_write_config32(PCI_DEV(0, 0x00, 0), PCIEXBAR, DEFAULT_PCIEXBAR | 5); /* 64MB - busses 0-63 */
166 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1);
167 pci_write_config32(PCI_DEV(0, 0x00, 0), X60BAR, DEFAULT_X60BAR | 1);
169 /* Hardware default is 8MB UMA. If someone wants to make this a
170 * CMOS or compile time option, send a patch.
171 * pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, 0x30);
174 /* Set C0000-FFFFF to access RAM on both reads and writes */
175 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
176 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
177 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
178 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
179 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
180 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
181 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
183 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
184 printk(BIOS_DEBUG, " done.\n");
186 /* Wait for MCH BAR to come up */
187 printk(BIOS_DEBUG, "Waiting for MCHBAR to come up...");
188 if ((pci_read_config8(PCI_DEV(0, 0x0f, 0), 0xe6) & 0x2) == 0x00) { /* Bit 49 of CAPID0 */
190 reg8 = *(volatile u8 *)0xfed40000;
191 } while (!(reg8 & 0x80));
193 printk(BIOS_DEBUG, "ok\n");
196 static void i945_setup_egress_port(void)
201 printk(BIOS_DEBUG, "Setting up Egress Port RCRB\n");
203 /* Egress Port Virtual Channel 0 Configuration */
205 /* map only TC0 to VC0 */
206 reg32 = EPBAR32(EPVC0RCTL);
208 EPBAR32(EPVC0RCTL) = reg32;
210 reg32 = EPBAR32(EPPVCCAP1);
213 EPBAR32(EPPVCCAP1) = reg32;
215 /* Egress Port Virtual Channel 1 Configuration */
216 reg32 = EPBAR32(0x2c);
218 if ((MCHBAR32(CLKCFG) & 7) == 1)
219 reg32 |= 0x0d; /* 533MHz */
220 if ((MCHBAR32(CLKCFG) & 7) == 3)
221 reg32 |= 0x10; /* 667MHz */
222 EPBAR32(0x2c) = reg32;
224 EPBAR32(EPVC1MTS) = 0x0a0a0a0a;
226 reg32 = EPBAR32(EPVC1RCAP);
227 reg32 &= ~(0x7f << 16);
228 reg32 |= (0x0a << 16);
229 EPBAR32(EPVC1RCAP) = reg32;
231 if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */
232 EPBAR32(EPVC1IST + 0) = 0x009c009c;
233 EPBAR32(EPVC1IST + 4) = 0x009c009c;
236 if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */
237 EPBAR32(EPVC1IST + 0) = 0x00c000c0;
238 EPBAR32(EPVC1IST + 4) = 0x00c000c0;
241 /* Is internal graphics enabled? */
242 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 0x54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
243 MCHBAR32(MMARB1) |= (1 << 17);
246 /* Assign Virtual Channel ID 1 to VC1 */
247 reg32 = EPBAR32(EPVC1RCTL);
250 EPBAR32(EPVC1RCTL) = reg32;
252 reg32 = EPBAR32(EPVC1RCTL);
255 EPBAR32(EPVC1RCTL) = reg32;
257 EPBAR32(PORTARB + 0x00) = 0x01000001;
258 EPBAR32(PORTARB + 0x04) = 0x00040000;
259 EPBAR32(PORTARB + 0x08) = 0x00001000;
260 EPBAR32(PORTARB + 0x0c) = 0x00000040;
261 EPBAR32(PORTARB + 0x10) = 0x01000001;
262 EPBAR32(PORTARB + 0x14) = 0x00040000;
263 EPBAR32(PORTARB + 0x18) = 0x00001000;
264 EPBAR32(PORTARB + 0x1c) = 0x00000040;
266 EPBAR32(EPVC1RCTL) |= (1 << 16);
267 EPBAR32(EPVC1RCTL) |= (1 << 16);
269 printk(BIOS_DEBUG, "Loading port arbitration table ...");
270 /* Loop until bit 0 becomes 0 */
272 while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) ;
274 printk(BIOS_DEBUG, "timeout!\n");
276 printk(BIOS_DEBUG, "ok\n");
279 EPBAR32(EPVC1RCTL) |= (1 << 31);
281 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
282 /* Wait for VC1 negotiation pending */
284 while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) ;
286 printk(BIOS_DEBUG, "timeout!\n");
288 printk(BIOS_DEBUG, "ok\n");
292 static void ich7_setup_dmi_rcrb(void)
297 reg16 = RCBA16(LCTL);
300 RCBA16(LCTL) = reg16;
302 RCBA32(V0CTL) = 0x80000001;
303 RCBA32(V1CAP) = 0x03128010;
304 RCBA32(ESD) = 0x00000810;
305 RCBA32(RP1D) = 0x01000003;
306 RCBA32(RP2D) = 0x02000002;
307 RCBA32(RP3D) = 0x03000002;
308 RCBA32(RP4D) = 0x04000002;
309 RCBA32(HDD) = 0x0f000003;
310 RCBA32(RP5D) = 0x05000002;
312 RCBA32(RPFN) = 0x00543210;
314 pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
315 pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
316 pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
318 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
319 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
321 reg32 = RCBA32(V1CTL);
322 reg32 &= ~( (0x7f << 1) | (7 << 17) | (7 << 24) );
323 reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31);
324 RCBA32(V1CTL) = reg32;
326 RCBA32(ESD) |= (2 << 16);
328 RCBA32(ULD) |= (1 << 24) | (1 << 16);
330 RCBA32(ULBA) = DEFAULT_DMIBAR;
332 RCBA32(RP1D) |= (2 << 16);
333 RCBA32(RP2D) |= (2 << 16);
334 RCBA32(RP3D) |= (2 << 16);
335 RCBA32(RP4D) |= (2 << 16);
336 RCBA32(HDD) |= (2 << 16);
337 RCBA32(RP5D) |= (2 << 16);
338 RCBA32(RP6D) |= (2 << 16);
340 RCBA32(LCAP) |= (3 << 10);
343 static void i945_setup_dmi_rcrb(void)
348 int activate_aspm = 1;
350 printk(BIOS_DEBUG, "Setting up DMI RCRB\n");
352 /* Virtual Channel 0 Configuration */
353 reg32 = DMIBAR32(DMIVC0RCTL0);
355 DMIBAR32(DMIVC0RCTL0) = reg32;
357 reg32 = DMIBAR32(DMIPVCCAP1);
360 DMIBAR32(DMIPVCCAP1) = reg32;
362 reg32 = DMIBAR32(DMIVC1RCTL);
364 reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
365 DMIBAR32(DMIVC1RCTL) = reg32;
367 reg32 = DMIBAR32(DMIVC1RCTL);
370 DMIBAR32(DMIVC1RCTL) = reg32;
373 DMIBAR32(DMIVC1RCTL) |= (1 << 31);
375 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
376 /* Wait for VC1 negotiation pending */
378 while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) ;
380 printk(BIOS_DEBUG, "timeout!\n");
382 printk(BIOS_DEBUG, "done..\n");
384 /* Enable Active State Power Management (ASPM) L0 state */
386 reg32 = DMIBAR32(DMILCAP);
393 DMIBAR32(DMILCAP) = reg32;
395 reg32 = DMIBAR32(DMICC);
402 DMIBAR32(DMICC) = reg32;
405 DMIBAR32(DMILCTL) |= (3 << 0);
409 /* Last but not least, some additional steps */
410 reg32 = MCHBAR32(FSBSNPCTL);
411 reg32 &= ~(0xff << 2);
412 reg32 |= (0xaa << 2);
413 MCHBAR32(FSBSNPCTL) = reg32;
415 DMIBAR32(0x2c) = 0x86000040;
417 reg32 = DMIBAR32(0x204);
420 reg32 |= 0x13f; /* for x4 DMI only */
422 reg32 |= 0x1e4; /* for x2 DMI only */
424 DMIBAR32(0x204) = reg32;
426 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 0x54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
427 printk(BIOS_DEBUG, "Internal graphics: enabled\n");
428 DMIBAR32(0x200) |= (1 << 21);
430 printk(BIOS_DEBUG, "Internal graphics: disabled\n");
431 DMIBAR32(0x200) &= ~(1 << 21);
434 reg32 = DMIBAR32(0x204);
435 reg32 &= ~((1 << 11) | (1 << 10));
436 DMIBAR32(0x204) = reg32;
438 reg32 = DMIBAR32(0x204);
439 reg32 &= ~(0xff << 12);
440 reg32 |= (0x0d << 12);
441 DMIBAR32(0x204) = reg32;
443 DMIBAR32(DMICTL1) |= (3 << 24);
445 reg32 = DMIBAR32(0x200);
446 reg32 &= ~(0x3 << 26);
447 reg32 |= (0x02 << 26);
448 DMIBAR32(0x200) = reg32;
450 DMIBAR32(DMIDRCCFG) &= ~(1 << 31);
451 DMIBAR32(DMICTL2) |= (1 << 31);
453 if (i945_silicon_revision() >= 3) {
454 reg32 = DMIBAR32(0xec0);
457 DMIBAR32(0xec0) = reg32;
459 reg32 = DMIBAR32(0xed4);
462 DMIBAR32(0xed4) = reg32;
464 reg32 = DMIBAR32(0xee8);
467 DMIBAR32(0xee8) = reg32;
469 reg32 = DMIBAR32(0xefc);
472 DMIBAR32(0xefc) = reg32;
475 /* wait for bit toggle to 0 */
476 printk(BIOS_DEBUG, "Waiting for DMI hardware...");
478 while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) ;
480 printk(BIOS_DEBUG, "timeout!\n");
482 printk(BIOS_DEBUG, "ok\n");
484 DMIBAR32(0x1c4) = 0xffffffff;
485 DMIBAR32(0x1d0) = 0xffffffff;
486 DMIBAR32(0x228) = 0xffffffff;
488 DMIBAR32(0x308) = DMIBAR32(0x308);
489 DMIBAR32(0x314) = DMIBAR32(0x314);
490 DMIBAR32(0x324) = DMIBAR32(0x324);
491 DMIBAR32(0x328) = DMIBAR32(0x328);
492 DMIBAR32(0x338) = DMIBAR32(0x334);
493 DMIBAR32(0x338) = DMIBAR32(0x338);
495 if (i945_silicon_revision() == 1 && ((MCHBAR8(0xe08) & (1 << 5)) == 1)) {
496 if ((MCHBAR32(0x214) & 0xf) != 0x3) {
497 printk(BIOS_INFO, "DMI link requires A1 stepping workaround. Rebooting.\n");
498 reg32 = DMIBAR32(0x224);
501 DMIBAR32(0x224) = reg32;
503 for (;;) ; /* wait for reset */
508 static void i945_setup_pci_express_x16(void)
516 printk(BIOS_DEBUG, "Enabling PCI Express x16 Link\n");
518 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
520 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
522 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x208);
524 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x208, reg32);
526 /* We have no success with querying the usual PCIe registers
527 * for link setup success on the i945. Hence we assign a temporary
528 * PCI bus 0x0a and check whether we find a device on 0:a.0
531 /* First we reset the secondary bus */
532 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
534 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
535 /* Read back and clear reset bit. */
536 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
538 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
540 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xba);
541 printk(BIOS_DEBUG, "SLOTSTS: %04x\n", reg16);
542 if (!(reg16 & 0x48)) {
543 goto disable_pciexpress_x16_link;
545 reg16 |= (1 << 4) | (1 << 0);
546 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xba, reg16);
548 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x00);
549 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x00);
550 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x0a);
551 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x0a);
553 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
555 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
557 MCHBAR16(UPMC1) &= ~( (1 << 5) | (1 << 0) );
559 /* Initialze PEG_CAP */
560 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0xa2);
562 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0xa2, reg16);
565 /* TODO: These values are mainboard dependent and should
566 * be set from Config.lb or Options.lb.
568 /* NOTE: SLOTCAP becomes RO after the first write! */
569 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xb4);
574 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xb4, reg32);
576 /* Wait for training to succeed */
577 printk(BIOS_DEBUG, "PCIe link training ...");
579 while ((((pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
581 reg32 = pci_read_config32(PCI_DEV(0x0a, 0x0, 0), 0);
582 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
583 printk(BIOS_DEBUG, " Detected PCIe device %04x:%04x\n",
584 reg32 & 0xffff, reg32 >> 16);
586 printk(BIOS_DEBUG, " timeout!\n");
588 printk(BIOS_DEBUG, "Restrain PCIe port to x1\n");
590 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
591 reg32 &= ~(0xf << 1);
593 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x214, reg32);
595 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
598 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
600 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
602 printk(BIOS_DEBUG, "PCIe link training ...");
604 while ((((pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
606 reg32 = pci_read_config32(PCI_DEV(0xa, 0x00, 0), 0);
607 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
608 printk(BIOS_DEBUG, " Detected PCIe x1 device %04x:%04x\n",
609 reg32 & 0xffff, reg32 >> 16);
611 printk(BIOS_DEBUG, " timeout!\n");
612 printk(BIOS_DEBUG, "Disabling PCIe x16 port completely.\n");
613 goto disable_pciexpress_x16_link;
617 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0xb2);
620 /* reg16 == 1 -> x1; reg16 == 16 -> x16 */
621 printk(BIOS_DEBUG, "PCIe x%d link training succeeded.\n", reg16);
623 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x204);
624 reg32 &= 0xfffffc00; /* clear [9:0] */
628 } else if (reg16 == 16) {
633 reg32 = (pci_read_config32(PCI_DEV(0xa, 0, 0), 0x8) >> 8);
634 printk(BIOS_DEBUG, "PCIe device class: %06x\n", reg32);
635 if (reg32 == 0x030000) {
636 printk(BIOS_DEBUG, "PCIe device is VGA. Disabling IGD.\n");
638 pci_write_config16(PCI_DEV(0, 0x0, 0), 0x52, reg16);
641 reg32 = pci_read_config32(PCI_DEV(0, 0x0, 0), 0x54);
642 reg32 &= ~((1 << 3) | (1 << 4));
643 pci_write_config32(PCI_DEV(0, 0x0, 0), 0x54, reg32);
645 /* Set VGA enable bit in PCIe bridge */
646 reg16 = pci_read_config16(PCI_DEV(0, 0x1, 0), 0x3e);
648 pci_write_config16(PCI_DEV(0, 0x1, 0), 0x3e, reg16);
652 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xec);
653 reg32 |= (1 << 2) | (1 << 1) | (1 << 0); /* PMEGPE, HPGPE, GENGPE */
654 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
656 /* Virtual Channel Configuration: Only VC0 on PCIe x16 */
657 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x114);
659 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
661 /* Extended VC count */
662 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x104);
664 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x104, reg32);
666 /* Active State Power Management ASPM */
670 /* Clear error bits */
671 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x06, 0xffff);
672 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x1e, 0xffff);
673 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0xaa, 0xffff);
674 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1c4, 0xffffffff);
675 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1d0, 0xffffffff);
676 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1f0, 0xffffffff);
677 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x228, 0xffffffff);
679 /* Program R/WO registers */
680 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x308);
681 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x308, reg32);
683 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x314);
684 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x314, reg32);
686 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x324);
687 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x324, reg32);
689 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x328);
690 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x328, reg32);
692 reg8 = pcie_read_config8(PCI_DEV(0, 0x01, 0), 0xb4);
693 pcie_write_config8(PCI_DEV(0, 0x01, 0), 0xb4, reg8);
695 /* Additional PCIe graphics setup */
696 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
698 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
700 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
702 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
704 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
706 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
708 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x200);
711 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x200, reg32);
713 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
714 if (i945_silicon_revision() >= 2) {
719 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
721 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xeb4);
723 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xeb4, reg32);
725 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xfc);
727 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xfc, reg32);
729 if (i945_silicon_revision() >= 3) {
730 static const u32 reglist[] = {
731 0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24,
732 0xf38, 0xf4c, 0xf60, 0xf74, 0xf88, 0xf9c,
733 0xfb0, 0xfc4, 0xfd8, 0xfec
737 for (i=0; i<ARRAY_SIZE(reglist); i++) {
738 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), reglist[i]);
741 pcie_write_config32(PCI_DEV(0, 0x01, 0), reglist[i], reg32);
745 if (i945_silicon_revision() <= 2 ) {
746 /* Set voltage specific parameters */
747 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
749 if ((MCHBAR32(0xe08) & (1 << 20)) == 0) {
752 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
757 disable_pciexpress_x16_link:
758 /* For now we just disable the x16 link */
759 printk(BIOS_DEBUG, "Disabling PCI Express x16 Link\n");
761 MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0);
763 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
765 pcie_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
767 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
769 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
771 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
773 pcie_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
775 printk(BIOS_DEBUG, "Wait for link to enter detect state... ");
777 for (reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
778 (reg32 & 0x000f0000) && --timeout;) ;
780 printk(BIOS_DEBUG, "timeout!\n");
782 printk(BIOS_DEBUG, "ok\n");
784 /* Finally: Disable the PCI config header */
785 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
786 reg16 &= ~DEVEN_D1F0;
787 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
790 static void i945_setup_root_complex_topology(void)
794 printk(BIOS_DEBUG, "Setting up Root Complex Topology\n");
795 /* Egress Port Root Topology */
797 reg32 = EPBAR32(EPESD);
800 EPBAR32(EPESD) = reg32;
802 EPBAR32(EPLE1D) |= (1 << 16) | (1 << 0);
804 EPBAR32(EPLE1A) = DEFAULT_DMIBAR;
806 EPBAR32(EPLE2D) |= (1 << 16) | (1 << 0);
808 /* DMI Port Root Topology */
810 reg32 = DMIBAR32(DMILE1D);
817 DMIBAR32(DMILE1D) = reg32;
819 DMIBAR32(DMILE1A) = DEFAULT_RCBA;
821 DMIBAR32(DMILE2D) |= (1 << 16) | (1 << 0);
823 DMIBAR32(DMILE2A) = DEFAULT_EPBAR;
825 /* PCI Express x16 Port Root Topology */
826 if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) {
827 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x158, DEFAULT_EPBAR);
828 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x150);
830 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32);
834 static void ich7_setup_root_complex_topology(void)
836 RCBA32(0x104) = 0x00000802;
837 RCBA32(0x110) = 0x00000001;
838 RCBA32(0x114) = 0x00000000;
839 RCBA32(0x118) = 0x00000000;
842 static void ich7_setup_pci_express(void)
844 RCBA32(CG) |= (1 << 0);
846 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
848 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
851 static void i945_early_initialization(void)
853 /* Print some chipset specific information */
854 switch (pci_read_config32(PCI_DEV(0, 0x00, 0), 0)) {
856 i945_detect_chipset();
860 i945m_detect_chipset();
864 /* Setup all BARs required for early PCIe and raminit */
867 /* Change port80 to LPC */
868 RCBA32(GCS) &= (~0x04);
870 /* Just do it that way */
871 RCBA32(0x2010) |= (1 << 10);
874 static void i945_late_initialization(void)
876 i945_setup_egress_port();
878 ich7_setup_root_complex_topology();
880 ich7_setup_pci_express();
882 ich7_setup_dmi_rcrb();
884 i945_setup_dmi_rcrb();
886 i945_setup_pci_express_x16();
888 i945_setup_root_complex_topology();