2 * This file is part of the coreboot project.
4 * Copyright (C) 2007-2010 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
22 #include <console/console.h>
24 #include <arch/romcc_io.h>
25 #include <device/pci_def.h>
27 #include "pcie_config.c"
29 int i945_silicon_revision(void)
31 return pci_read_config8(PCI_DEV(0, 0x00, 0), PCI_CLASS_REVISION);
34 static void i945m_detect_chipset(void)
38 printk(BIOS_INFO, "\n");
39 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) & 0x70) >> 4;
42 printk(BIOS_INFO, "Mobile Intel(R) 82945GM/GME Express");
45 printk(BIOS_INFO, "Mobile Intel(R) 82945GMS/GU/GSE Express");
48 printk(BIOS_INFO, "Mobile Intel(R) 82945PM Express");
51 printk(BIOS_INFO, "Intel(R) 82945GT Express");
54 printk(BIOS_INFO, "Mobile Intel(R) 82943/82940GML Express");
57 printk(BIOS_INFO, "Unknown (%02x)", reg8); /* Others reserved. */
59 printk(BIOS_INFO, " Chipset\n");
61 printk(BIOS_DEBUG, "(G)MCH capable of up to FSB ");
62 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe3) & 0xe0) >> 5;
65 printk(BIOS_DEBUG, "800 MHz"); /* According to 965 spec */
68 printk(BIOS_DEBUG, "667 MHz");
71 printk(BIOS_DEBUG, "533 MHz");
74 printk(BIOS_DEBUG, "N/A MHz (%02x)", reg8);
76 printk(BIOS_DEBUG, "\n");
78 printk(BIOS_DEBUG, "(G)MCH capable of ");
79 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
82 printk(BIOS_DEBUG, "up to DDR2-667");
85 printk(BIOS_DEBUG, "up to DDR2-533");
88 printk(BIOS_DEBUG, "DDR2-400");
91 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
93 printk(BIOS_DEBUG, "\n");
94 #if CONFIG_NORTHBRIDGE_INTEL_I945GC
95 printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
99 static void i945_detect_chipset(void)
103 printk(BIOS_INFO, "\nIntel(R) ");
105 reg8 = ((pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) >> 5) & 4) | ((pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) >> 4) & 3);
109 printk(BIOS_INFO, "82945G");
113 printk(BIOS_INFO, "82945P");
116 printk(BIOS_INFO, "82945GC");
119 printk(BIOS_INFO, "82945GZ");
123 printk(BIOS_INFO, "82945PL");
128 printk(BIOS_INFO, " Chipset\n");
130 printk(BIOS_DEBUG, "(G)MCH capable of ");
131 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
134 printk(BIOS_DEBUG, "up to DDR2-667");
137 printk(BIOS_DEBUG, "up to DDR2-533");
140 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
142 printk(BIOS_DEBUG, "\n");
143 #if CONFIG_NORTHBRIDGE_INTEL_I945GM
144 printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
148 static void i945_setup_bars(void)
152 /* As of now, we don't have all the A0 workarounds implemented */
153 if (i945_silicon_revision() == 0)
154 printk(BIOS_INFO, "Warning: i945 silicon revision A0 might not work correctly.\n");
156 /* Setting up Southbridge. In the northbridge code. */
157 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
158 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1);
160 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
161 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
163 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
164 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); /* Enable GPIOs */
166 printk(BIOS_DEBUG, " done.\n");
168 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
169 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
170 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
171 printk(BIOS_DEBUG, " done.\n");
173 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
174 /* Set up all hardcoded northbridge BARs */
175 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
176 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
177 pci_write_config32(PCI_DEV(0, 0x00, 0), PCIEXBAR, DEFAULT_PCIEXBAR | 5); /* 64MB - busses 0-63 */
178 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1);
179 pci_write_config32(PCI_DEV(0, 0x00, 0), X60BAR, DEFAULT_X60BAR | 1);
181 /* Hardware default is 8MB UMA. If someone wants to make this a
182 * CMOS or compile time option, send a patch.
183 * pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, 0x30);
186 /* Set C0000-FFFFF to access RAM on both reads and writes */
187 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
188 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
189 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
190 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
191 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
192 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
193 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
195 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, SKPAD_NORMAL_BOOT_MAGIC);
196 printk(BIOS_DEBUG, " done.\n");
198 /* Wait for MCH BAR to come up */
199 printk(BIOS_DEBUG, "Waiting for MCHBAR to come up...");
200 if ((pci_read_config8(PCI_DEV(0, 0x0f, 0), 0xe6) & 0x2) == 0x00) { /* Bit 49 of CAPID0 */
202 reg8 = *(volatile u8 *)0xfed40000;
203 } while (!(reg8 & 0x80));
205 printk(BIOS_DEBUG, "ok\n");
208 static void i945_setup_egress_port(void)
213 printk(BIOS_DEBUG, "Setting up Egress Port RCRB\n");
215 /* Egress Port Virtual Channel 0 Configuration */
217 /* map only TC0 to VC0 */
218 reg32 = EPBAR32(EPVC0RCTL);
220 EPBAR32(EPVC0RCTL) = reg32;
222 reg32 = EPBAR32(EPPVCCAP1);
225 EPBAR32(EPPVCCAP1) = reg32;
227 /* Egress Port Virtual Channel 1 Configuration */
228 reg32 = EPBAR32(0x2c);
230 if ((MCHBAR32(CLKCFG) & 7) == 1)
231 reg32 |= 0x0d; /* 533MHz */
232 if ((MCHBAR32(CLKCFG) & 7) == 3)
233 reg32 |= 0x10; /* 667MHz */
234 EPBAR32(0x2c) = reg32;
236 EPBAR32(EPVC1MTS) = 0x0a0a0a0a;
238 reg32 = EPBAR32(EPVC1RCAP);
239 reg32 &= ~(0x7f << 16);
240 reg32 |= (0x0a << 16);
241 EPBAR32(EPVC1RCAP) = reg32;
243 if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */
244 EPBAR32(EPVC1IST + 0) = 0x009c009c;
245 EPBAR32(EPVC1IST + 4) = 0x009c009c;
248 if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */
249 EPBAR32(EPVC1IST + 0) = 0x00c000c0;
250 EPBAR32(EPVC1IST + 4) = 0x00c000c0;
253 /* Is internal graphics enabled? */
254 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 0x54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
255 MCHBAR32(MMARB1) |= (1 << 17);
258 /* Assign Virtual Channel ID 1 to VC1 */
259 reg32 = EPBAR32(EPVC1RCTL);
262 EPBAR32(EPVC1RCTL) = reg32;
264 reg32 = EPBAR32(EPVC1RCTL);
267 EPBAR32(EPVC1RCTL) = reg32;
269 EPBAR32(PORTARB + 0x00) = 0x01000001;
270 EPBAR32(PORTARB + 0x04) = 0x00040000;
271 EPBAR32(PORTARB + 0x08) = 0x00001000;
272 EPBAR32(PORTARB + 0x0c) = 0x00000040;
273 EPBAR32(PORTARB + 0x10) = 0x01000001;
274 EPBAR32(PORTARB + 0x14) = 0x00040000;
275 EPBAR32(PORTARB + 0x18) = 0x00001000;
276 EPBAR32(PORTARB + 0x1c) = 0x00000040;
278 EPBAR32(EPVC1RCTL) |= (1 << 16);
279 EPBAR32(EPVC1RCTL) |= (1 << 16);
281 printk(BIOS_DEBUG, "Loading port arbitration table ...");
282 /* Loop until bit 0 becomes 0 */
284 while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) ;
286 printk(BIOS_DEBUG, "timeout!\n");
288 printk(BIOS_DEBUG, "ok\n");
291 EPBAR32(EPVC1RCTL) |= (1 << 31);
293 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
294 /* Wait for VC1 negotiation pending */
296 while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) ;
298 printk(BIOS_DEBUG, "timeout!\n");
300 printk(BIOS_DEBUG, "ok\n");
304 static void ich7_setup_dmi_rcrb(void)
309 reg16 = RCBA16(LCTL);
312 RCBA16(LCTL) = reg16;
314 RCBA32(V0CTL) = 0x80000001;
315 RCBA32(V1CAP) = 0x03128010;
316 RCBA32(ESD) = 0x00000810;
317 RCBA32(RP1D) = 0x01000003;
318 RCBA32(RP2D) = 0x02000002;
319 RCBA32(RP3D) = 0x03000002;
320 RCBA32(RP4D) = 0x04000002;
321 RCBA32(HDD) = 0x0f000003;
322 RCBA32(RP5D) = 0x05000002;
324 RCBA32(RPFN) = 0x00543210;
326 pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
327 pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
328 pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
330 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
331 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
333 reg32 = RCBA32(V1CTL);
334 reg32 &= ~( (0x7f << 1) | (7 << 17) | (7 << 24) );
335 reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31);
336 RCBA32(V1CTL) = reg32;
338 RCBA32(ESD) |= (2 << 16);
340 RCBA32(ULD) |= (1 << 24) | (1 << 16);
342 RCBA32(ULBA) = DEFAULT_DMIBAR;
344 RCBA32(RP1D) |= (2 << 16);
345 RCBA32(RP2D) |= (2 << 16);
346 RCBA32(RP3D) |= (2 << 16);
347 RCBA32(RP4D) |= (2 << 16);
348 RCBA32(HDD) |= (2 << 16);
349 RCBA32(RP5D) |= (2 << 16);
350 RCBA32(RP6D) |= (2 << 16);
352 RCBA32(LCAP) |= (3 << 10);
355 static void i945_setup_dmi_rcrb(void)
359 int activate_aspm = 1; /* hardcode ASPM for now */
361 printk(BIOS_DEBUG, "Setting up DMI RCRB\n");
363 /* Virtual Channel 0 Configuration */
364 reg32 = DMIBAR32(DMIVC0RCTL0);
366 DMIBAR32(DMIVC0RCTL0) = reg32;
368 reg32 = DMIBAR32(DMIPVCCAP1);
371 DMIBAR32(DMIPVCCAP1) = reg32;
373 reg32 = DMIBAR32(DMIVC1RCTL);
375 reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
376 DMIBAR32(DMIVC1RCTL) = reg32;
378 reg32 = DMIBAR32(DMIVC1RCTL);
381 DMIBAR32(DMIVC1RCTL) = reg32;
384 DMIBAR32(DMIVC1RCTL) |= (1 << 31);
386 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
387 /* Wait for VC1 negotiation pending */
389 while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) ;
391 printk(BIOS_DEBUG, "timeout!\n");
393 printk(BIOS_DEBUG, "done..\n");
395 /* Enable Active State Power Management (ASPM) L0 state */
397 reg32 = DMIBAR32(DMILCAP);
404 DMIBAR32(DMILCAP) = reg32;
406 reg32 = DMIBAR32(DMICC);
413 DMIBAR32(DMICC) = reg32;
416 DMIBAR32(DMILCTL) |= (3 << 0);
420 /* Last but not least, some additional steps */
421 reg32 = MCHBAR32(FSBSNPCTL);
422 reg32 &= ~(0xff << 2);
423 reg32 |= (0xaa << 2);
424 MCHBAR32(FSBSNPCTL) = reg32;
426 DMIBAR32(0x2c) = 0x86000040;
428 reg32 = DMIBAR32(0x204);
431 reg32 |= 0x13f; /* for x4 DMI only */
433 reg32 |= 0x1e4; /* for x2 DMI only */
435 DMIBAR32(0x204) = reg32;
437 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 0x54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
438 printk(BIOS_DEBUG, "Internal graphics: enabled\n");
439 DMIBAR32(0x200) |= (1 << 21);
441 printk(BIOS_DEBUG, "Internal graphics: disabled\n");
442 DMIBAR32(0x200) &= ~(1 << 21);
445 reg32 = DMIBAR32(0x204);
446 reg32 &= ~((1 << 11) | (1 << 10));
447 DMIBAR32(0x204) = reg32;
449 reg32 = DMIBAR32(0x204);
450 reg32 &= ~(0xff << 12);
451 reg32 |= (0x0d << 12);
452 DMIBAR32(0x204) = reg32;
454 DMIBAR32(DMICTL1) |= (3 << 24);
456 reg32 = DMIBAR32(0x200);
457 reg32 &= ~(0x3 << 26);
458 reg32 |= (0x02 << 26);
459 DMIBAR32(0x200) = reg32;
461 DMIBAR32(DMIDRCCFG) &= ~(1 << 31);
462 DMIBAR32(DMICTL2) |= (1 << 31);
464 if (i945_silicon_revision() >= 3) {
465 reg32 = DMIBAR32(0xec0);
468 DMIBAR32(0xec0) = reg32;
470 reg32 = DMIBAR32(0xed4);
473 DMIBAR32(0xed4) = reg32;
475 reg32 = DMIBAR32(0xee8);
478 DMIBAR32(0xee8) = reg32;
480 reg32 = DMIBAR32(0xefc);
483 DMIBAR32(0xefc) = reg32;
486 /* wait for bit toggle to 0 */
487 printk(BIOS_DEBUG, "Waiting for DMI hardware...");
489 while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) ;
491 printk(BIOS_DEBUG, "timeout!\n");
493 printk(BIOS_DEBUG, "ok\n");
495 /* Clear Error Status Bits! */
496 DMIBAR32(0x1c4) = 0xffffffff;
497 DMIBAR32(0x1d0) = 0xffffffff;
498 DMIBAR32(0x228) = 0xffffffff;
500 /* Program Read-Only Write-Once Registers */
501 DMIBAR32(0x308) = DMIBAR32(0x308);
502 DMIBAR32(0x314) = DMIBAR32(0x314);
503 DMIBAR32(0x324) = DMIBAR32(0x324);
504 DMIBAR32(0x328) = DMIBAR32(0x328);
505 DMIBAR32(0x338) = DMIBAR32(0x334);
506 DMIBAR32(0x338) = DMIBAR32(0x338);
508 if (i945_silicon_revision() == 1 && ((MCHBAR8(0xe08) & (1 << 5)) == 1)) {
509 if ((MCHBAR32(0x214) & 0xf) != 0x3) {
510 printk(BIOS_INFO, "DMI link requires A1 stepping workaround. Rebooting.\n");
511 reg32 = DMIBAR32(0x224);
514 DMIBAR32(0x224) = reg32;
516 for (;;) asm("hlt"); /* wait for reset */
521 static void i945_setup_pci_express_x16(void)
529 printk(BIOS_DEBUG, "Enabling PCI Express x16 Link\n");
531 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
533 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
535 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x208);
537 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x208, reg32);
539 /* We have no success with querying the usual PCIe registers
540 * for link setup success on the i945. Hence we assign a temporary
541 * PCI bus 0x0a and check whether we find a device on 0:a.0
544 /* First we reset the secondary bus */
545 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
546 reg16 |= (1 << 6); /* SRESET */
547 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
548 /* Read back and clear reset bit. */
549 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
550 reg16 &= ~(1 << 6); /* SRESET */
551 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
553 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xba);
554 printk(BIOS_DEBUG, "SLOTSTS: %04x\n", reg16);
555 if (!(reg16 & 0x48)) {
556 goto disable_pciexpress_x16_link;
558 reg16 |= (1 << 4) | (1 << 0);
559 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xba, reg16);
561 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x00);
562 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x00);
563 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x0a);
564 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x0a);
566 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
568 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
570 MCHBAR16(UPMC1) &= ~( (1 << 5) | (1 << 0) );
572 /* Initialze PEG_CAP */
573 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0xa2);
575 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0xa2, reg16);
578 /* TODO: These values are mainboard dependent and should
579 * be set from devicetree.cb.
581 /* NOTE: SLOTCAP becomes RO after the first write! */
582 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xb4);
587 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xb4, reg32);
589 /* Wait for training to succeed */
590 printk(BIOS_DEBUG, "PCIe link training ...");
592 while ((((pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
594 reg32 = pci_read_config32(PCI_DEV(0x0a, 0x0, 0), 0);
595 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
596 printk(BIOS_DEBUG, " Detected PCIe device %04x:%04x\n",
597 reg32 & 0xffff, reg32 >> 16);
599 printk(BIOS_DEBUG, " timeout!\n");
601 printk(BIOS_DEBUG, "Restrain PCIe port to x1\n");
603 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
604 reg32 &= ~(0xf << 1);
606 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x214, reg32);
608 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
611 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
613 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
615 printk(BIOS_DEBUG, "PCIe link training ...");
617 while ((((pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
619 reg32 = pci_read_config32(PCI_DEV(0xa, 0x00, 0), 0);
620 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
621 printk(BIOS_DEBUG, " Detected PCIe x1 device %04x:%04x\n",
622 reg32 & 0xffff, reg32 >> 16);
624 printk(BIOS_DEBUG, " timeout!\n");
625 printk(BIOS_DEBUG, "Disabling PCIe x16 port completely.\n");
626 goto disable_pciexpress_x16_link;
630 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0xb2);
633 /* reg16 == 1 -> x1; reg16 == 16 -> x16 */
634 printk(BIOS_DEBUG, "PCIe x%d link training succeeded.\n", reg16);
636 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x204);
637 reg32 &= 0xfffffc00; /* clear [9:0] */
641 /* pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
642 } else if (reg16 == 16) {
645 /* pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
648 reg32 = (pci_read_config32(PCI_DEV(0xa, 0, 0), 0x8) >> 8);
649 printk(BIOS_DEBUG, "PCIe device class: %06x\n", reg32);
650 if (reg32 == 0x030000) {
651 printk(BIOS_DEBUG, "PCIe device is VGA. Disabling IGD.\n");
653 pci_write_config16(PCI_DEV(0, 0x0, 0), 0x52, reg16);
656 reg32 = pci_read_config32(PCI_DEV(0, 0x0, 0), 0x54);
657 reg32 &= ~((1 << 3) | (1 << 4));
658 pci_write_config32(PCI_DEV(0, 0x0, 0), 0x54, reg32);
660 /* Set VGA enable bit in PCIe bridge */
661 reg16 = pci_read_config16(PCI_DEV(0, 0x1, 0), 0x3e);
663 pci_write_config16(PCI_DEV(0, 0x1, 0), 0x3e, reg16);
667 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xec);
668 reg32 |= (1 << 2) | (1 << 1) | (1 << 0); /* PMEGPE, HPGPE, GENGPE */
669 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
671 /* Virtual Channel Configuration: Only VC0 on PCIe x16 */
672 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x114);
674 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
676 /* Extended VC count */
677 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x104);
679 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x104, reg32);
681 /* Active State Power Management ASPM */
685 /* Clear error bits */
686 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x06, 0xffff);
687 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x1e, 0xffff);
688 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0xaa, 0xffff);
689 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1c4, 0xffffffff);
690 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1d0, 0xffffffff);
691 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1f0, 0xffffffff);
692 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x228, 0xffffffff);
694 /* Program R/WO registers */
695 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x308);
696 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x308, reg32);
698 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x314);
699 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x314, reg32);
701 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x324);
702 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x324, reg32);
704 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x328);
705 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x328, reg32);
707 reg8 = pcie_read_config8(PCI_DEV(0, 0x01, 0), 0xb4);
708 pcie_write_config8(PCI_DEV(0, 0x01, 0), 0xb4, reg8);
710 /* Additional PCIe graphics setup */
711 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
713 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
715 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
717 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
719 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
721 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
723 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x200);
726 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x200, reg32);
728 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
729 if (i945_silicon_revision() >= 2) {
734 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
736 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xeb4);
738 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xeb4, reg32);
740 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xfc);
742 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xfc, reg32);
744 if (i945_silicon_revision() >= 3) {
745 static const u32 reglist[] = {
746 0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24,
747 0xf38, 0xf4c, 0xf60, 0xf74, 0xf88, 0xf9c,
748 0xfb0, 0xfc4, 0xfd8, 0xfec
752 for (i=0; i<ARRAY_SIZE(reglist); i++) {
753 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), reglist[i]);
756 pcie_write_config32(PCI_DEV(0, 0x01, 0), reglist[i], reg32);
760 if (i945_silicon_revision() <= 2 ) {
761 /* Set voltage specific parameters */
762 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
763 reg32 &= (0xf << 4); /* Default case 1.05V */
764 if ((MCHBAR32(0xe08) & (1 << 20)) == 0) { /* 1.50V */
767 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
772 disable_pciexpress_x16_link:
773 /* For now we just disable the x16 link */
774 printk(BIOS_DEBUG, "Disabling PCI Express x16 Link\n");
776 MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0);
778 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
780 pcie_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
782 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
784 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
786 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
788 pcie_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
790 printk(BIOS_DEBUG, "Wait for link to enter detect state... ");
792 for (reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
793 (reg32 & 0x000f0000) && --timeout;) ;
795 printk(BIOS_DEBUG, "timeout!\n");
797 printk(BIOS_DEBUG, "ok\n");
799 /* Finally: Disable the PCI config header */
800 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
801 reg16 &= ~DEVEN_D1F0;
802 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
805 static void i945_setup_root_complex_topology(void)
809 printk(BIOS_DEBUG, "Setting up Root Complex Topology\n");
810 /* Egress Port Root Topology */
812 reg32 = EPBAR32(EPESD);
815 EPBAR32(EPESD) = reg32;
817 EPBAR32(EPLE1D) |= (1 << 16) | (1 << 0);
819 EPBAR32(EPLE1A) = DEFAULT_DMIBAR;
821 EPBAR32(EPLE2D) |= (1 << 16) | (1 << 0);
823 /* DMI Port Root Topology */
825 reg32 = DMIBAR32(DMILE1D);
832 DMIBAR32(DMILE1D) = reg32;
834 DMIBAR32(DMILE1A) = DEFAULT_RCBA;
836 DMIBAR32(DMILE2D) |= (1 << 16) | (1 << 0);
838 DMIBAR32(DMILE2A) = DEFAULT_EPBAR;
840 /* PCI Express x16 Port Root Topology */
841 if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) {
842 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x158, DEFAULT_EPBAR);
843 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x150);
845 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32);
849 static void ich7_setup_root_complex_topology(void)
851 RCBA32(0x104) = 0x00000802;
852 RCBA32(0x110) = 0x00000001;
853 RCBA32(0x114) = 0x00000000;
854 RCBA32(0x118) = 0x00000000;
857 static void ich7_setup_pci_express(void)
859 RCBA32(CG) |= (1 << 0);
861 /* Initialize slot power limit for root ports */
862 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
864 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
865 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
868 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
871 void i945_early_initialization(void)
873 /* Print some chipset specific information */
874 switch (pci_read_config32(PCI_DEV(0, 0x00, 0), 0)) {
875 case 0x27708086: /* 82945G/GZ/GC/P/PL */
876 i945_detect_chipset();
878 case 0x27a08086: /* 945GME/GSE */
879 case 0x27ac8086: /* 945GM/PM/GMS/GU/GT, 943/940GML */
880 i945m_detect_chipset();
884 /* Setup all BARs required for early PCIe and raminit */
887 /* Change port80 to LPC */
888 RCBA32(GCS) &= (~0x04);
890 /* Just do it that way */
891 RCBA32(0x2010) |= (1 << 10);
894 void i945_late_initialization(void)
896 i945_setup_egress_port();
898 ich7_setup_root_complex_topology();
900 ich7_setup_pci_express();
902 ich7_setup_dmi_rcrb();
904 i945_setup_dmi_rcrb();
906 i945_setup_pci_express_x16();
908 i945_setup_root_complex_topology();