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)
33 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) & 0x70) >> 4;
36 printk_info("Mobile Intel(R) 82945GM/GME Express");
39 printk_info("Mobile Intel(R) 82945GMS/GU Express");
42 printk_info("Mobile Intel(R) 82945PM Express");
45 printk_info("Intel(R) 82945GT Express");
48 printk_info("Mobile Intel(R) 82943/82940GML Express");
51 printk_info("Unknown (%02x)", reg8); /* Others reserved. */
53 printk_info(" Chipset\n");
55 printk_debug("(G)MCH capable of up to FSB ");
56 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe3) & 0xe0) >> 5;
59 printk_debug("800 MHz"); /* According to 965 spec */
62 printk_debug("667 MHz");
65 printk_debug("533 MHz");
68 printk_debug("N/A MHz (%02x)", reg8);
72 printk_debug("(G)MCH capable of ");
73 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
76 printk_debug("up to DDR2-667");
79 printk_debug("up to DDR2-533");
82 printk_debug("DDR2-400");
85 printk_info("unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
90 static void i945_detect_chipset(void)
94 printk_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_info("82945G");
104 printk_info("82945P");
107 printk_info("82945GC");
110 printk_info("82945GZ");
114 printk_info("82945PL");
119 printk_info(" Chipset\n");
121 printk_debug("(G)MCH capable of ");
122 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
125 printk_debug("up to DDR2-667");
128 printk_debug("up to DDR2-533");
131 printk_info("unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
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)
143 ("Warning: i945 silicon revision A0 might not work correctly.\n");
145 /* Setting up Southbridge. In the northbridge code. */
146 printk_debug("Setting up static southbridge registers...");
147 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1);
149 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
150 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
152 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
153 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); /* Enable GPIOs */
155 printk_debug(" done.\n");
157 printk_debug("Disabling Watchdog reboot...");
158 RCBA32(GCS) = (RCBA32(0x3410)) | (1 << 5); /* No reset */
159 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
160 printk_debug(" done.\n");
162 printk_debug("Setting up static northbridge registers...");
163 /* Set up all hardcoded northbridge BARs */
164 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
165 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
166 pci_write_config32(PCI_DEV(0, 0x00, 0), PCIEXBAR, DEFAULT_PCIEXBAR | 5); /* 64MB - busses 0-63 */
167 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1);
168 pci_write_config32(PCI_DEV(0, 0x00, 0), X60BAR, DEFAULT_X60BAR | 1);
170 /* Hardware default is 8MB UMA. If someone wants to make this a
171 * CMOS or compile time option, send a patch.
172 * pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, 0x30);
175 /* Set C0000-FFFFF to access RAM on both reads and writes */
176 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
177 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
178 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
179 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
180 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
181 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
182 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
184 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
185 printk_debug(" done.\n");
187 /* Wait for MCH BAR to come up */
188 printk_debug("Waiting for MCHBAR to come up...");
189 if ((pci_read_config8(PCI_DEV(0, 0x0f, 0), 0xe6) & 0x2) == 0x00) { /* Bit 49 of CAPID0 */
191 reg8 = *(volatile u8 *)0xfed40000;
192 } while (!(reg8 & 0x80));
194 printk_debug("ok\n");
197 static void i945_setup_egress_port(void)
202 printk_debug("Setting up Egress Port RCRB\n");
204 /* Egress Port Virtual Channel 0 Configuration */
206 /* map only TC0 to VC0 */
207 reg32 = EPBAR32(EPVC0RCTL);
209 EPBAR32(EPVC0RCTL) = reg32;
211 reg32 = EPBAR32(EPPVCCAP1);
214 EPBAR32(EPPVCCAP1) = reg32;
216 /* Egress Port Virtual Channel 1 Configuration */
217 reg32 = EPBAR32(0x2c);
219 if ((MCHBAR32(CLKCFG) & 7) == 1)
220 reg32 |= 0x0d; /* 533MHz */
221 if ((MCHBAR32(CLKCFG) & 7) == 3)
222 reg32 |= 0x10; /* 667MHz */
223 EPBAR32(0x2c) = reg32;
225 EPBAR32(EPVC1MTS) = 0x0a0a0a0a;
227 reg32 = EPBAR32(EPVC1RCAP);
228 reg32 &= ~(0x7f << 16);
229 reg32 |= (0x0a << 16);
230 EPBAR32(EPVC1RCAP) = reg32;
232 if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */
233 EPBAR32(EPVC1IST + 0) = 0x009c009c;
234 EPBAR32(EPVC1IST + 4) = 0x009c009c;
237 if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */
238 EPBAR32(EPVC1IST + 0) = 0x00c000c0;
239 EPBAR32(EPVC1IST + 4) = 0x00c000c0;
242 /* Is internal graphics enabled? */
243 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 0x54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
244 MCHBAR32(MMARB1) |= (1 << 17);
247 /* Assign Virtual Channel ID 1 to VC1 */
248 reg32 = EPBAR32(EPVC1RCTL);
251 EPBAR32(EPVC1RCTL) = reg32;
253 reg32 = EPBAR32(EPVC1RCTL);
256 EPBAR32(EPVC1RCTL) = reg32;
258 EPBAR32(PORTARB + 0x00) = 0x01000001;
259 EPBAR32(PORTARB + 0x04) = 0x00040000;
260 EPBAR32(PORTARB + 0x08) = 0x00001000;
261 EPBAR32(PORTARB + 0x0c) = 0x00000040;
262 EPBAR32(PORTARB + 0x10) = 0x01000001;
263 EPBAR32(PORTARB + 0x14) = 0x00040000;
264 EPBAR32(PORTARB + 0x18) = 0x00001000;
265 EPBAR32(PORTARB + 0x1c) = 0x00000040;
267 EPBAR32(EPVC1RCTL) |= (1 << 16);
268 EPBAR32(EPVC1RCTL) |= (1 << 16);
270 printk_debug("Loading port arbitration table ...");
271 /* Loop until bit 0 becomes 0 */
273 while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) ;
275 printk_debug("timeout!\n");
277 printk_debug("ok\n");
280 EPBAR32(EPVC1RCTL) |= (1 << 31);
282 printk_debug("Wait for VC1 negotiation ...");
283 /* Wait for VC1 negotiation pending */
285 while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) ;
287 printk_debug("timeout!\n");
289 printk_debug("ok\n");
293 static void ich7_setup_dmi_rcrb(void)
298 reg16 = RCBA16(LCTL);
301 RCBA16(LCTL) = reg16;
303 RCBA32(V0CTL) = 0x80000001;
304 RCBA32(V1CAP) = 0x03128010;
305 RCBA32(ESD) = 0x00000810;
306 RCBA32(RP1D) = 0x01000003;
307 RCBA32(RP2D) = 0x02000002;
308 RCBA32(RP3D) = 0x03000002;
309 RCBA32(RP4D) = 0x04000002;
310 RCBA32(HDD) = 0x0f000003;
311 RCBA32(RP5D) = 0x05000002;
313 RCBA32(RPFN) = 0x00543210;
315 pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
316 pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
317 pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
319 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
320 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
322 reg32 = RCBA32(V1CTL);
323 reg32 &= ~( (0x7f << 1) | (7 << 17) | (7 << 24) );
324 reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31);
325 RCBA32(V1CTL) = reg32;
327 RCBA32(ESD) |= (2 << 16);
329 RCBA32(ULD) |= (1 << 24) | (1 << 16);
331 RCBA32(ULBA) = DEFAULT_DMIBAR;
333 RCBA32(RP1D) |= (2 << 16);
334 RCBA32(RP2D) |= (2 << 16);
335 RCBA32(RP3D) |= (2 << 16);
336 RCBA32(RP4D) |= (2 << 16);
337 RCBA32(HDD) |= (2 << 16);
338 RCBA32(RP5D) |= (2 << 16);
339 RCBA32(RP6D) |= (2 << 16);
341 RCBA32(LCAP) |= (3 << 10);
344 static void i945_setup_dmi_rcrb(void)
349 int activate_aspm = 1;
351 printk_debug("Setting up DMI RCRB\n");
353 /* Virtual Channel 0 Configuration */
354 reg32 = DMIBAR32(DMIVC0RCTL0);
356 DMIBAR32(DMIVC0RCTL0) = reg32;
358 reg32 = DMIBAR32(DMIPVCCAP1);
361 DMIBAR32(DMIPVCCAP1) = reg32;
363 reg32 = DMIBAR32(DMIVC1RCTL);
365 reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
366 DMIBAR32(DMIVC1RCTL) = reg32;
368 reg32 = DMIBAR32(DMIVC1RCTL);
371 DMIBAR32(DMIVC1RCTL) = reg32;
374 DMIBAR32(DMIVC1RCTL) |= (1 << 31);
376 printk_debug("Wait for VC1 negotiation ...");
377 /* Wait for VC1 negotiation pending */
379 while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) ;
381 printk_debug("timeout!\n");
383 printk_debug("done..\n");
385 /* Enable Active State Power Management (ASPM) L0 state */
387 reg32 = DMIBAR32(DMILCAP);
394 DMIBAR32(DMILCAP) = reg32;
396 reg32 = DMIBAR32(DMICC);
403 DMIBAR32(DMICC) = reg32;
406 DMIBAR32(DMILCTL) |= (3 << 0);
410 /* Last but not least, some additional steps */
411 reg32 = MCHBAR32(FSBSNPCTL);
412 reg32 &= ~(0xff << 2);
413 reg32 |= (0xaa << 2);
414 MCHBAR32(FSBSNPCTL) = reg32;
416 DMIBAR32(0x2c) = 0x86000040;
418 reg32 = DMIBAR32(0x204);
421 reg32 |= 0x13f; /* for x4 DMI only */
423 reg32 |= 0x1e4; /* for x2 DMI only */
425 DMIBAR32(0x204) = reg32;
427 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 0x54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
428 printk_debug("Internal graphics: enabled\n");
429 DMIBAR32(0x200) |= (1 << 21);
431 printk_debug("Internal graphics: disabled\n");
432 DMIBAR32(0x200) &= ~(1 << 21);
435 reg32 = DMIBAR32(0x204);
436 reg32 &= ~((1 << 11) | (1 << 10));
437 DMIBAR32(0x204) = reg32;
439 reg32 = DMIBAR32(0x204);
440 reg32 &= ~(0xff << 12);
441 reg32 |= (0x0d << 12);
442 DMIBAR32(0x204) = reg32;
444 DMIBAR32(DMICTL1) |= (3 << 24);
446 reg32 = DMIBAR32(0x200);
447 reg32 &= ~(0x3 << 26);
448 reg32 |= (0x02 << 26);
449 DMIBAR32(0x200) = reg32;
451 DMIBAR32(DMIDRCCFG) &= ~(1 << 31);
452 DMIBAR32(DMICTL2) |= (1 << 31);
454 if (i945_silicon_revision() >= 3) {
455 reg32 = DMIBAR32(0xec0);
458 DMIBAR32(0xec0) = reg32;
460 reg32 = DMIBAR32(0xed4);
463 DMIBAR32(0xed4) = reg32;
465 reg32 = DMIBAR32(0xee8);
468 DMIBAR32(0xee8) = reg32;
470 reg32 = DMIBAR32(0xefc);
473 DMIBAR32(0xefc) = reg32;
476 /* wait for bit toggle to 0 */
477 printk_debug("Waiting for DMI hardware...");
479 while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) ;
481 printk_debug("timeout!\n");
483 printk_debug("ok\n");
485 DMIBAR32(0x1c4) = 0xffffffff;
486 DMIBAR32(0x1d0) = 0xffffffff;
487 DMIBAR32(0x228) = 0xffffffff;
489 DMIBAR32(0x308) = DMIBAR32(0x308);
490 DMIBAR32(0x314) = DMIBAR32(0x314);
491 DMIBAR32(0x324) = DMIBAR32(0x324);
492 DMIBAR32(0x328) = DMIBAR32(0x328);
493 DMIBAR32(0x338) = DMIBAR32(0x334);
494 DMIBAR32(0x338) = DMIBAR32(0x338);
496 if (i945_silicon_revision() == 1 && ((MCHBAR8(0xe08) & (1 << 5)) == 1)) {
497 if ((MCHBAR32(0x214) & 0xf) != 0x3) {
499 ("DMI link requires A1 stepping workaround. Rebooting.\n");
500 reg32 = DMIBAR32(0x224);
503 DMIBAR32(0x224) = reg32;
505 for (;;) ; /* wait for reset */
510 static void i945_setup_pci_express_x16(void)
518 printk_debug("Enabling PCI Express x16 Link\n");
520 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
522 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
524 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x208);
526 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x208, reg32);
528 /* We have no success with querying the usual PCIe registers
529 * for link setup success on the i945. Hence we assign a temporary
530 * PCI bus 0x0a and check whether we find a device on 0:a.0
533 /* First we reset the secondary bus */
534 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
536 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
537 /* Read back and clear reset bit. */
538 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
540 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
542 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xba);
543 printk_debug("SLOTSTS: %04x\n", reg16);
544 if (!(reg16 & 0x48)) {
545 goto disable_pciexpress_x16_link;
547 reg16 |= (1 << 4) | (1 << 0);
548 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xba, reg16);
550 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x00);
551 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x00);
552 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x0a);
553 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x0a);
555 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
557 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
559 MCHBAR16(UPMC1) &= ~( (1 << 5) | (1 << 0) );
561 /* Initialze PEG_CAP */
562 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0xa2);
564 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0xa2, reg16);
567 /* TODO: These values are mainboard dependent and should
568 * be set from Config.lb or Options.lb.
570 /* NOTE: SLOTCAP becomes RO after the first write! */
571 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xb4);
576 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xb4, reg32);
578 /* Wait for training to succeed */
579 printk_debug("PCIe link training ...");
581 while ((((pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
583 reg32 = pci_read_config32(PCI_DEV(0x0a, 0x0, 0), 0);
584 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
585 printk_debug(" Detected PCIe device %04x:%04x\n",
586 reg32 & 0xffff, reg32 >> 16);
588 printk_debug(" timeout!\n");
590 printk_debug("Restrain PCIe port to x1\n");
592 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
593 reg32 &= ~(0xf << 1);
595 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x214, reg32);
597 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
600 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
602 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
604 printk_debug("PCIe link training ...");
606 while ((((pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
608 reg32 = pci_read_config32(PCI_DEV(0xa, 0x00, 0), 0);
609 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
610 printk_debug(" Detected PCIe x1 device %04x:%04x\n",
611 reg32 & 0xffff, reg32 >> 16);
613 printk_debug(" timeout!\n");
614 printk_debug("Disabling PCIe x16 port completely.\n");
615 goto disable_pciexpress_x16_link;
619 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0xb2);
622 /* reg16 == 1 -> x1; reg16 == 16 -> x16 */
623 printk_debug("PCIe x%d link training succeeded.\n", reg16);
625 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x204);
626 reg32 &= 0xfffffc00; /* clear [9:0] */
630 } else if (reg16 == 16) {
635 reg32 = (pci_read_config32(PCI_DEV(0xa, 0, 0), 0x8) >> 8);
636 printk_debug("PCIe device class: %06x\n", reg32);
637 if (reg32 == 0x030000) {
638 printk_debug("PCIe device is VGA. Disabling IGD.\n");
640 pci_write_config16(PCI_DEV(0, 0x0, 0), 0x52, reg16);
643 reg32 = pci_read_config32(PCI_DEV(0, 0x0, 0), 0x54);
644 reg32 &= ~((1 << 3) | (1 << 4));
645 pci_write_config32(PCI_DEV(0, 0x0, 0), 0x54, reg32);
647 /* Set VGA enable bit in PCIe bridge */
648 reg16 = pci_read_config16(PCI_DEV(0, 0x1, 0), 0x3e);
650 pci_write_config16(PCI_DEV(0, 0x1, 0), 0x3e, reg16);
654 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xec);
655 reg32 |= (1 << 2) | (1 << 1) | (1 << 0); /* PMEGPE, HPGPE, GENGPE */
656 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
658 /* Virtual Channel Configuration: Only VC0 on PCIe x16 */
659 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x114);
661 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
663 /* Extended VC count */
664 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x104);
666 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x104, reg32);
668 /* Active State Power Management ASPM */
672 /* Clear error bits */
673 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x06, 0xffff);
674 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x1e, 0xffff);
675 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0xaa, 0xffff);
676 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1c4, 0xffffffff);
677 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1d0, 0xffffffff);
678 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1f0, 0xffffffff);
679 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x228, 0xffffffff);
681 /* Program R/WO registers */
682 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x308);
683 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x308, reg32);
685 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x314);
686 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x314, reg32);
688 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x324);
689 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x324, reg32);
691 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x328);
692 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x328, reg32);
694 reg8 = pcie_read_config8(PCI_DEV(0, 0x01, 0), 0xb4);
695 pcie_write_config8(PCI_DEV(0, 0x01, 0), 0xb4, reg8);
697 /* Additional PCIe graphics setup */
698 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
700 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
702 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
704 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
706 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
708 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
710 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x200);
713 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x200, reg32);
715 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
716 if (i945_silicon_revision() >= 2) {
721 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
723 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xeb4);
725 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xeb4, reg32);
727 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xfc);
729 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xfc, reg32);
731 if (i945_silicon_revision() >= 3) {
732 static const u32 reglist[] = {
733 0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24,
734 0xf38, 0xf4c, 0xf60, 0xf74, 0xf88, 0xf9c,
735 0xfb0, 0xfc4, 0xfd8, 0xfec
739 for (i=0; i<ARRAY_SIZE(reglist); i++) {
740 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), reglist[i]);
743 pcie_write_config32(PCI_DEV(0, 0x01, 0), reglist[i], reg32);
747 if (i945_silicon_revision() <= 2 ) {
748 /* Set voltage specific parameters */
749 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
751 if ((MCHBAR32(0xe08) & (1 << 20)) == 0) {
754 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
759 disable_pciexpress_x16_link:
760 /* For now we just disable the x16 link */
761 printk_debug("Disabling PCI Express x16 Link\n");
763 MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0);
765 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
767 pcie_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
769 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
771 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
773 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
775 pcie_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
777 printk_debug("Wait for link to enter detect state... ");
779 for (reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
780 (reg32 & 0x000f0000) && --timeout;) ;
782 printk_debug("timeout!\n");
784 printk_debug("ok\n");
786 /* Finally: Disable the PCI config header */
787 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
788 reg16 &= ~DEVEN_D1F0;
789 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
792 static void i945_setup_root_complex_topology(void)
796 printk_debug("Setting up Root Complex Topology\n");
797 /* Egress Port Root Topology */
799 reg32 = EPBAR32(EPESD);
802 EPBAR32(EPESD) = reg32;
804 EPBAR32(EPLE1D) |= (1 << 16) | (1 << 0);
806 EPBAR32(EPLE1A) = DEFAULT_DMIBAR;
808 EPBAR32(EPLE2D) |= (1 << 16) | (1 << 0);
810 /* DMI Port Root Topology */
812 reg32 = DMIBAR32(DMILE1D);
819 DMIBAR32(DMILE1D) = reg32;
821 DMIBAR32(DMILE1A) = DEFAULT_RCBA;
823 DMIBAR32(DMILE2D) |= (1 << 16) | (1 << 0);
825 DMIBAR32(DMILE2A) = DEFAULT_EPBAR;
827 /* PCI Express x16 Port Root Topology */
828 if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) {
829 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x158, DEFAULT_EPBAR);
830 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x150);
832 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32);
836 static void ich7_setup_root_complex_topology(void)
838 RCBA32(0x104) = 0x00000802;
839 RCBA32(0x110) = 0x00000001;
840 RCBA32(0x114) = 0x00000000;
841 RCBA32(0x118) = 0x00000000;
844 static void ich7_setup_pci_express(void)
846 RCBA32(CG) |= (1 << 0);
848 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
850 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
853 static void i945_early_initialization(void)
855 /* Print some chipset specific information */
856 switch (pci_read_config32(PCI_DEV(0, 0x00, 0), 0)) {
858 i945_detect_chipset();
862 i945m_detect_chipset();
866 /* Setup all BARs required for early PCIe and raminit */
869 /* Change port80 to LPC */
870 RCBA32(GCS) &= (~0x04);
872 /* Just do it that way */
873 RCBA32(0x2010) |= (1 << 10);
876 static void i945_late_initialization(void)
878 i945_setup_egress_port();
880 ich7_setup_root_complex_topology();
882 ich7_setup_pci_express();
884 ich7_setup_dmi_rcrb();
886 i945_setup_dmi_rcrb();
888 i945_setup_pci_express_x16();
890 i945_setup_root_complex_topology();