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 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");
96 static void i945_detect_chipset(void)
100 printk(BIOS_INFO, "\nIntel(R) ");
102 reg8 = ((pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) >> 5) & 4) | ((pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) >> 4) & 3);
106 printk(BIOS_INFO, "82945G");
110 printk(BIOS_INFO, "82945P");
113 printk(BIOS_INFO, "82945GC");
116 printk(BIOS_INFO, "82945GZ");
120 printk(BIOS_INFO, "82945PL");
125 printk(BIOS_INFO, " Chipset\n");
127 printk(BIOS_DEBUG, "(G)MCH capable of ");
128 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07);
131 printk(BIOS_DEBUG, "up to DDR2-667");
134 printk(BIOS_DEBUG, "up to DDR2-533");
137 printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */
139 printk(BIOS_DEBUG, "\n");
142 static void i945_setup_bars(void)
146 /* As of now, we don't have all the A0 workarounds implemented */
147 if (i945_silicon_revision() == 0)
148 printk(BIOS_INFO, "Warning: i945 silicon revision A0 might not work correctly.\n");
150 /* Setting up Southbridge. In the northbridge code. */
151 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
152 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1);
154 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
155 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
157 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
158 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); /* Enable GPIOs */
160 printk(BIOS_DEBUG, " done.\n");
162 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
163 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
164 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
165 printk(BIOS_DEBUG, " done.\n");
167 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
168 /* Set up all hardcoded northbridge BARs */
169 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
170 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
171 pci_write_config32(PCI_DEV(0, 0x00, 0), PCIEXBAR, DEFAULT_PCIEXBAR | 5); /* 64MB - busses 0-63 */
172 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1);
173 pci_write_config32(PCI_DEV(0, 0x00, 0), X60BAR, DEFAULT_X60BAR | 1);
175 /* Hardware default is 8MB UMA. If someone wants to make this a
176 * CMOS or compile time option, send a patch.
177 * pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, 0x30);
180 /* Set C0000-FFFFF to access RAM on both reads and writes */
181 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
182 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
183 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
184 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
185 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
186 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
187 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
189 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
190 printk(BIOS_DEBUG, " done.\n");
192 /* Wait for MCH BAR to come up */
193 printk(BIOS_DEBUG, "Waiting for MCHBAR to come up...");
194 if ((pci_read_config8(PCI_DEV(0, 0x0f, 0), 0xe6) & 0x2) == 0x00) { /* Bit 49 of CAPID0 */
196 reg8 = *(volatile u8 *)0xfed40000;
197 } while (!(reg8 & 0x80));
199 printk(BIOS_DEBUG, "ok\n");
202 static void i945_setup_egress_port(void)
207 printk(BIOS_DEBUG, "Setting up Egress Port RCRB\n");
209 /* Egress Port Virtual Channel 0 Configuration */
211 /* map only TC0 to VC0 */
212 reg32 = EPBAR32(EPVC0RCTL);
214 EPBAR32(EPVC0RCTL) = reg32;
216 reg32 = EPBAR32(EPPVCCAP1);
219 EPBAR32(EPPVCCAP1) = reg32;
221 /* Egress Port Virtual Channel 1 Configuration */
222 reg32 = EPBAR32(0x2c);
224 if ((MCHBAR32(CLKCFG) & 7) == 1)
225 reg32 |= 0x0d; /* 533MHz */
226 if ((MCHBAR32(CLKCFG) & 7) == 3)
227 reg32 |= 0x10; /* 667MHz */
228 EPBAR32(0x2c) = reg32;
230 EPBAR32(EPVC1MTS) = 0x0a0a0a0a;
232 reg32 = EPBAR32(EPVC1RCAP);
233 reg32 &= ~(0x7f << 16);
234 reg32 |= (0x0a << 16);
235 EPBAR32(EPVC1RCAP) = reg32;
237 if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */
238 EPBAR32(EPVC1IST + 0) = 0x009c009c;
239 EPBAR32(EPVC1IST + 4) = 0x009c009c;
242 if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */
243 EPBAR32(EPVC1IST + 0) = 0x00c000c0;
244 EPBAR32(EPVC1IST + 4) = 0x00c000c0;
247 /* Is internal graphics enabled? */
248 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 0x54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
249 MCHBAR32(MMARB1) |= (1 << 17);
252 /* Assign Virtual Channel ID 1 to VC1 */
253 reg32 = EPBAR32(EPVC1RCTL);
256 EPBAR32(EPVC1RCTL) = reg32;
258 reg32 = EPBAR32(EPVC1RCTL);
261 EPBAR32(EPVC1RCTL) = reg32;
263 EPBAR32(PORTARB + 0x00) = 0x01000001;
264 EPBAR32(PORTARB + 0x04) = 0x00040000;
265 EPBAR32(PORTARB + 0x08) = 0x00001000;
266 EPBAR32(PORTARB + 0x0c) = 0x00000040;
267 EPBAR32(PORTARB + 0x10) = 0x01000001;
268 EPBAR32(PORTARB + 0x14) = 0x00040000;
269 EPBAR32(PORTARB + 0x18) = 0x00001000;
270 EPBAR32(PORTARB + 0x1c) = 0x00000040;
272 EPBAR32(EPVC1RCTL) |= (1 << 16);
273 EPBAR32(EPVC1RCTL) |= (1 << 16);
275 printk(BIOS_DEBUG, "Loading port arbitration table ...");
276 /* Loop until bit 0 becomes 0 */
278 while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) ;
280 printk(BIOS_DEBUG, "timeout!\n");
282 printk(BIOS_DEBUG, "ok\n");
285 EPBAR32(EPVC1RCTL) |= (1 << 31);
287 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
288 /* Wait for VC1 negotiation pending */
290 while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) ;
292 printk(BIOS_DEBUG, "timeout!\n");
294 printk(BIOS_DEBUG, "ok\n");
298 static void ich7_setup_dmi_rcrb(void)
303 reg16 = RCBA16(LCTL);
306 RCBA16(LCTL) = reg16;
308 RCBA32(V0CTL) = 0x80000001;
309 RCBA32(V1CAP) = 0x03128010;
310 RCBA32(ESD) = 0x00000810;
311 RCBA32(RP1D) = 0x01000003;
312 RCBA32(RP2D) = 0x02000002;
313 RCBA32(RP3D) = 0x03000002;
314 RCBA32(RP4D) = 0x04000002;
315 RCBA32(HDD) = 0x0f000003;
316 RCBA32(RP5D) = 0x05000002;
318 RCBA32(RPFN) = 0x00543210;
320 pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
321 pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
322 pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
324 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
325 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
327 reg32 = RCBA32(V1CTL);
328 reg32 &= ~( (0x7f << 1) | (7 << 17) | (7 << 24) );
329 reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31);
330 RCBA32(V1CTL) = reg32;
332 RCBA32(ESD) |= (2 << 16);
334 RCBA32(ULD) |= (1 << 24) | (1 << 16);
336 RCBA32(ULBA) = DEFAULT_DMIBAR;
338 RCBA32(RP1D) |= (2 << 16);
339 RCBA32(RP2D) |= (2 << 16);
340 RCBA32(RP3D) |= (2 << 16);
341 RCBA32(RP4D) |= (2 << 16);
342 RCBA32(HDD) |= (2 << 16);
343 RCBA32(RP5D) |= (2 << 16);
344 RCBA32(RP6D) |= (2 << 16);
346 RCBA32(LCAP) |= (3 << 10);
349 static void i945_setup_dmi_rcrb(void)
353 int activate_aspm = 1; /* hardcode ASPM for now */
355 printk(BIOS_DEBUG, "Setting up DMI RCRB\n");
357 /* Virtual Channel 0 Configuration */
358 reg32 = DMIBAR32(DMIVC0RCTL0);
360 DMIBAR32(DMIVC0RCTL0) = reg32;
362 reg32 = DMIBAR32(DMIPVCCAP1);
365 DMIBAR32(DMIPVCCAP1) = reg32;
367 reg32 = DMIBAR32(DMIVC1RCTL);
369 reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
370 DMIBAR32(DMIVC1RCTL) = reg32;
372 reg32 = DMIBAR32(DMIVC1RCTL);
375 DMIBAR32(DMIVC1RCTL) = reg32;
378 DMIBAR32(DMIVC1RCTL) |= (1 << 31);
380 printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
381 /* Wait for VC1 negotiation pending */
383 while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) ;
385 printk(BIOS_DEBUG, "timeout!\n");
387 printk(BIOS_DEBUG, "done..\n");
389 /* Enable Active State Power Management (ASPM) L0 state */
391 reg32 = DMIBAR32(DMILCAP);
398 DMIBAR32(DMILCAP) = reg32;
400 reg32 = DMIBAR32(DMICC);
407 DMIBAR32(DMICC) = reg32;
410 DMIBAR32(DMILCTL) |= (3 << 0);
414 /* Last but not least, some additional steps */
415 reg32 = MCHBAR32(FSBSNPCTL);
416 reg32 &= ~(0xff << 2);
417 reg32 |= (0xaa << 2);
418 MCHBAR32(FSBSNPCTL) = reg32;
420 DMIBAR32(0x2c) = 0x86000040;
422 reg32 = DMIBAR32(0x204);
425 reg32 |= 0x13f; /* for x4 DMI only */
427 reg32 |= 0x1e4; /* for x2 DMI only */
429 DMIBAR32(0x204) = reg32;
431 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 0x54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
432 printk(BIOS_DEBUG, "Internal graphics: enabled\n");
433 DMIBAR32(0x200) |= (1 << 21);
435 printk(BIOS_DEBUG, "Internal graphics: disabled\n");
436 DMIBAR32(0x200) &= ~(1 << 21);
439 reg32 = DMIBAR32(0x204);
440 reg32 &= ~((1 << 11) | (1 << 10));
441 DMIBAR32(0x204) = reg32;
443 reg32 = DMIBAR32(0x204);
444 reg32 &= ~(0xff << 12);
445 reg32 |= (0x0d << 12);
446 DMIBAR32(0x204) = reg32;
448 DMIBAR32(DMICTL1) |= (3 << 24);
450 reg32 = DMIBAR32(0x200);
451 reg32 &= ~(0x3 << 26);
452 reg32 |= (0x02 << 26);
453 DMIBAR32(0x200) = reg32;
455 DMIBAR32(DMIDRCCFG) &= ~(1 << 31);
456 DMIBAR32(DMICTL2) |= (1 << 31);
458 if (i945_silicon_revision() >= 3) {
459 reg32 = DMIBAR32(0xec0);
462 DMIBAR32(0xec0) = reg32;
464 reg32 = DMIBAR32(0xed4);
467 DMIBAR32(0xed4) = reg32;
469 reg32 = DMIBAR32(0xee8);
472 DMIBAR32(0xee8) = reg32;
474 reg32 = DMIBAR32(0xefc);
477 DMIBAR32(0xefc) = reg32;
480 /* wait for bit toggle to 0 */
481 printk(BIOS_DEBUG, "Waiting for DMI hardware...");
483 while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) ;
485 printk(BIOS_DEBUG, "timeout!\n");
487 printk(BIOS_DEBUG, "ok\n");
489 /* Clear Error Status Bits! */
490 DMIBAR32(0x1c4) = 0xffffffff;
491 DMIBAR32(0x1d0) = 0xffffffff;
492 DMIBAR32(0x228) = 0xffffffff;
494 /* Program Read-Only Write-Once Registers */
495 DMIBAR32(0x308) = DMIBAR32(0x308);
496 DMIBAR32(0x314) = DMIBAR32(0x314);
497 DMIBAR32(0x324) = DMIBAR32(0x324);
498 DMIBAR32(0x328) = DMIBAR32(0x328);
499 DMIBAR32(0x338) = DMIBAR32(0x334);
500 DMIBAR32(0x338) = DMIBAR32(0x338);
502 if (i945_silicon_revision() == 1 && ((MCHBAR8(0xe08) & (1 << 5)) == 1)) {
503 if ((MCHBAR32(0x214) & 0xf) != 0x3) {
504 printk(BIOS_INFO, "DMI link requires A1 stepping workaround. Rebooting.\n");
505 reg32 = DMIBAR32(0x224);
508 DMIBAR32(0x224) = reg32;
510 for (;;) asm("hlt"); /* wait for reset */
515 static void i945_setup_pci_express_x16(void)
523 printk(BIOS_DEBUG, "Enabling PCI Express x16 Link\n");
525 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
527 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
529 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x208);
531 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x208, reg32);
533 /* We have no success with querying the usual PCIe registers
534 * for link setup success on the i945. Hence we assign a temporary
535 * PCI bus 0x0a and check whether we find a device on 0:a.0
538 /* First we reset the secondary bus */
539 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
540 reg16 |= (1 << 6); /* SRESET */
541 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
542 /* Read back and clear reset bit. */
543 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
544 reg16 &= ~(1 << 6); /* SRESET */
545 pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
547 reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xba);
548 printk(BIOS_DEBUG, "SLOTSTS: %04x\n", reg16);
549 if (!(reg16 & 0x48)) {
550 goto disable_pciexpress_x16_link;
552 reg16 |= (1 << 4) | (1 << 0);
553 pci_write_config16(PCI_DEV(0, 0x01, 0), 0xba, reg16);
555 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x00);
556 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x00);
557 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x0a);
558 pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x0a);
560 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
562 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
564 MCHBAR16(UPMC1) &= ~( (1 << 5) | (1 << 0) );
566 /* Initialze PEG_CAP */
567 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0xa2);
569 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0xa2, reg16);
572 /* TODO: These values are mainboard dependent and should
573 * be set from devicetree.cb.
575 /* NOTE: SLOTCAP becomes RO after the first write! */
576 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xb4);
581 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xb4, reg32);
583 /* Wait for training to succeed */
584 printk(BIOS_DEBUG, "PCIe link training ...");
586 while ((((pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
588 reg32 = pci_read_config32(PCI_DEV(0x0a, 0x0, 0), 0);
589 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
590 printk(BIOS_DEBUG, " Detected PCIe device %04x:%04x\n",
591 reg32 & 0xffff, reg32 >> 16);
593 printk(BIOS_DEBUG, " timeout!\n");
595 printk(BIOS_DEBUG, "Restrain PCIe port to x1\n");
597 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
598 reg32 &= ~(0xf << 1);
600 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x214, reg32);
602 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0x3e);
605 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
607 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16);
609 printk(BIOS_DEBUG, "PCIe link training ...");
611 while ((((pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214) >> 16) & 4) != 3) && --timeout) ;
613 reg32 = pci_read_config32(PCI_DEV(0xa, 0x00, 0), 0);
614 if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
615 printk(BIOS_DEBUG, " Detected PCIe x1 device %04x:%04x\n",
616 reg32 & 0xffff, reg32 >> 16);
618 printk(BIOS_DEBUG, " timeout!\n");
619 printk(BIOS_DEBUG, "Disabling PCIe x16 port completely.\n");
620 goto disable_pciexpress_x16_link;
624 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), 0xb2);
627 /* reg16 == 1 -> x1; reg16 == 16 -> x16 */
628 printk(BIOS_DEBUG, "PCIe x%d link training succeeded.\n", reg16);
630 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x204);
631 reg32 &= 0xfffffc00; /* clear [9:0] */
635 /* pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
636 } else if (reg16 == 16) {
639 /* pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */
642 reg32 = (pci_read_config32(PCI_DEV(0xa, 0, 0), 0x8) >> 8);
643 printk(BIOS_DEBUG, "PCIe device class: %06x\n", reg32);
644 if (reg32 == 0x030000) {
645 printk(BIOS_DEBUG, "PCIe device is VGA. Disabling IGD.\n");
647 pci_write_config16(PCI_DEV(0, 0x0, 0), 0x52, reg16);
650 reg32 = pci_read_config32(PCI_DEV(0, 0x0, 0), 0x54);
651 reg32 &= ~((1 << 3) | (1 << 4));
652 pci_write_config32(PCI_DEV(0, 0x0, 0), 0x54, reg32);
654 /* Set VGA enable bit in PCIe bridge */
655 reg16 = pci_read_config16(PCI_DEV(0, 0x1, 0), 0x3e);
657 pci_write_config16(PCI_DEV(0, 0x1, 0), 0x3e, reg16);
661 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xec);
662 reg32 |= (1 << 2) | (1 << 1) | (1 << 0); /* PMEGPE, HPGPE, GENGPE */
663 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
665 /* Virtual Channel Configuration: Only VC0 on PCIe x16 */
666 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x114);
668 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32);
670 /* Extended VC count */
671 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x104);
673 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x104, reg32);
675 /* Active State Power Management ASPM */
679 /* Clear error bits */
680 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x06, 0xffff);
681 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0x1e, 0xffff);
682 pcie_write_config16(PCI_DEV(0, 0x01, 0), 0xaa, 0xffff);
683 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1c4, 0xffffffff);
684 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1d0, 0xffffffff);
685 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x1f0, 0xffffffff);
686 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x228, 0xffffffff);
688 /* Program R/WO registers */
689 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x308);
690 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x308, reg32);
692 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x314);
693 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x314, reg32);
695 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x324);
696 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x324, reg32);
698 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x328);
699 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x328, reg32);
701 reg8 = pcie_read_config8(PCI_DEV(0, 0x01, 0), 0xb4);
702 pcie_write_config8(PCI_DEV(0, 0x01, 0), 0xb4, reg8);
704 /* Additional PCIe graphics setup */
705 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
707 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
709 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
711 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
713 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xf0);
715 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32);
717 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x200);
720 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x200, reg32);
722 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
723 if (i945_silicon_revision() >= 2) {
728 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
730 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xeb4);
732 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xeb4, reg32);
734 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xfc);
736 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xfc, reg32);
738 if (i945_silicon_revision() >= 3) {
739 static const u32 reglist[] = {
740 0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24,
741 0xf38, 0xf4c, 0xf60, 0xf74, 0xf88, 0xf9c,
742 0xfb0, 0xfc4, 0xfd8, 0xfec
746 for (i=0; i<ARRAY_SIZE(reglist); i++) {
747 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), reglist[i]);
750 pcie_write_config32(PCI_DEV(0, 0x01, 0), reglist[i], reg32);
754 if (i945_silicon_revision() <= 2 ) {
755 /* Set voltage specific parameters */
756 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0xe80);
757 reg32 &= (0xf << 4); /* Default case 1.05V */
758 if ((MCHBAR32(0xe08) & (1 << 20)) == 0) { /* 1.50V */
761 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32);
766 disable_pciexpress_x16_link:
767 /* For now we just disable the x16 link */
768 printk(BIOS_DEBUG, "Disabling PCI Express x16 Link\n");
770 MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0);
772 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
774 pcie_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
776 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
778 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
780 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
782 pcie_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
784 printk(BIOS_DEBUG, "Wait for link to enter detect state... ");
786 for (reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
787 (reg32 & 0x000f0000) && --timeout;) ;
789 printk(BIOS_DEBUG, "timeout!\n");
791 printk(BIOS_DEBUG, "ok\n");
793 /* Finally: Disable the PCI config header */
794 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
795 reg16 &= ~DEVEN_D1F0;
796 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
799 static void i945_setup_root_complex_topology(void)
803 printk(BIOS_DEBUG, "Setting up Root Complex Topology\n");
804 /* Egress Port Root Topology */
806 reg32 = EPBAR32(EPESD);
809 EPBAR32(EPESD) = reg32;
811 EPBAR32(EPLE1D) |= (1 << 16) | (1 << 0);
813 EPBAR32(EPLE1A) = DEFAULT_DMIBAR;
815 EPBAR32(EPLE2D) |= (1 << 16) | (1 << 0);
817 /* DMI Port Root Topology */
819 reg32 = DMIBAR32(DMILE1D);
826 DMIBAR32(DMILE1D) = reg32;
828 DMIBAR32(DMILE1A) = DEFAULT_RCBA;
830 DMIBAR32(DMILE2D) |= (1 << 16) | (1 << 0);
832 DMIBAR32(DMILE2A) = DEFAULT_EPBAR;
834 /* PCI Express x16 Port Root Topology */
835 if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) {
836 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x158, DEFAULT_EPBAR);
837 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x150);
839 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32);
843 static void ich7_setup_root_complex_topology(void)
845 RCBA32(0x104) = 0x00000802;
846 RCBA32(0x110) = 0x00000001;
847 RCBA32(0x114) = 0x00000000;
848 RCBA32(0x118) = 0x00000000;
851 static void ich7_setup_pci_express(void)
853 RCBA32(CG) |= (1 << 0);
855 /* Initialize slot power limit for root ports */
856 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
858 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
859 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
862 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
865 void i945_early_initialization(void)
867 /* Print some chipset specific information */
868 switch (pci_read_config32(PCI_DEV(0, 0x00, 0), 0)) {
869 case 0x27708086: /* 82945G/GZ/GC/P/PL */
870 i945_detect_chipset();
872 case 0x27a08086: /* 945GME/GSE */
873 case 0x27ac8086: /* 945GM/PM/GMS/GU/GT, 943/940GML */
874 i945m_detect_chipset();
878 /* Setup all BARs required for early PCIe and raminit */
881 /* Change port80 to LPC */
882 RCBA32(GCS) &= (~0x04);
884 /* Just do it that way */
885 RCBA32(0x2010) |= (1 << 10);
888 void i945_late_initialization(void)
890 i945_setup_egress_port();
892 ich7_setup_root_complex_topology();
894 ich7_setup_pci_express();
896 ich7_setup_dmi_rcrb();
898 i945_setup_dmi_rcrb();
900 i945_setup_pci_express_x16();
902 i945_setup_root_complex_topology();