2 * This file is part of the coreboot project.
4 * Copyright (C) 2007-2008 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 i945_detect_chipset(void)
33 reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) & 0x70) >> 4;
36 printk_info("Mobile Intel(R) 945GM/GME Express");
39 printk_info("Mobile Intel(R) 945GMS/GU Express");
42 printk_info("Mobile Intel(R) 945PM Express");
45 printk_info("Intel(R) 945GT Express");
48 printk_info("Mobile Intel(R) 943/940GML 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_setup_bars(void)
94 /* As of now, we don't have all the A0 workarounds implemented */
95 if (i945_silicon_revision() == 0)
97 ("Warning: i945 silicon revision A0 might not work correctly.\n");
99 /* Setting up Southbridge. In the northbridge code. */
100 printk_debug("Setting up static southbridge registers...");
101 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1);
103 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
104 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
106 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1);
107 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); /* Enable GPIOs */
109 printk_debug(" done.\n");
111 printk_debug("Disabling Watchdog reboot...");
112 RCBA32(GCS) = (RCBA32(0x3410)) | (1 << 5); /* No reset */
113 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
114 printk_debug(" done.\n");
116 printk_debug("Setting up static northbridge registers...");
117 /* Set up all hardcoded northbridge BARs */
118 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
119 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
120 pci_write_config32(PCI_DEV(0, 0x00, 0), PCIEXBAR, DEFAULT_PCIEXBAR | 5); /* 64MB - busses 0-63 */
121 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1);
122 pci_write_config32(PCI_DEV(0, 0x00, 0), X60BAR, DEFAULT_X60BAR | 1);
124 /* Hardware default is 8MB UMA. If someone wants to make this a
125 * CMOS or compile time option, send a patch.
126 * pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, 0x30);
129 /* Set C0000-FFFFF to access RAM on both reads and writes */
130 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
131 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
132 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
133 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
134 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
135 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
136 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
138 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
139 printk_debug(" done.\n");
141 /* Wait for MCH BAR to come up */
142 printk_debug("Waiting for MCHBAR to come up...");
143 if ((pci_read_config8(PCI_DEV(0, 0x0f, 0), 0xe6) & 0x2) == 0x00) { /* Bit 49 of CAPID0 */
145 reg8 = *(volatile u8 *)0xfed40000;
146 } while (!(reg8 & 0x80));
148 printk_debug("ok\n");
151 static void i945_setup_egress_port(void)
156 printk_debug("Setting up Egress Port RCRB\n");
158 /* Egress Port Virtual Channel 0 Configuration */
160 /* map only TC0 to VC0 */
161 reg32 = EPBAR32(EPVC0RCTL);
163 EPBAR32(EPVC0RCTL) = reg32;
166 reg32 = EPBAR32(EPPVCCAP1);
169 EPBAR32(EPPVCCAP1) = reg32;
171 /* Egress Port Virtual Channel 1 Configuration */
172 reg32 = EPBAR32(0x2c);
174 if ((MCHBAR32(CLKCFG) & 7) == 1)
175 reg32 |= 0x0d; /* 533MHz */
176 if ((MCHBAR32(CLKCFG) & 7) == 3)
177 reg32 |= 0x10; /* 667MHz */
178 EPBAR32(0x2c) = reg32;
180 EPBAR32(EPVC1MTS) = 0x0a0a0a0a;
182 reg32 = EPBAR32(EPVC1RCAP);
183 reg32 &= ~(0x7f << 16);
184 reg32 |= (0x0a << 16);
185 EPBAR32(EPVC1RCAP) = reg32;
187 if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */
188 EPBAR32(EPVC1IST + 0) = 0x009c009c;
189 EPBAR32(EPVC1IST + 4) = 0x009c009c;
192 if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */
193 EPBAR32(EPVC1IST + 0) = 0x00c000c0;
194 EPBAR32(EPVC1IST + 4) = 0x00c000c0;
197 /* Is internal graphics enabled? */
198 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
199 MCHBAR32(MMARB1) |= (1 << 17);
202 /* Assign Virtual Channel ID 1 to VC1 */
203 reg32 = EPBAR32(EPVC1RCTL);
206 EPBAR32(EPVC1RCTL) = reg32;
208 reg32 = EPBAR32(EPVC1RCTL);
211 EPBAR32(EPVC1RCTL) = reg32;
213 EPBAR32(PORTARB + 0x00) = 0x01000001;
214 EPBAR32(PORTARB + 0x04) = 0x00040000;
215 EPBAR32(PORTARB + 0x08) = 0x00001000;
216 EPBAR32(PORTARB + 0x0c) = 0x00000040;
217 EPBAR32(PORTARB + 0x10) = 0x01000001;
218 EPBAR32(PORTARB + 0x14) = 0x00040000;
219 EPBAR32(PORTARB + 0x18) = 0x00001000;
220 EPBAR32(PORTARB + 0x1c) = 0x00000040;
222 EPBAR32(EPVC1RCTL) |= (1 << 16);
223 EPBAR32(EPVC1RCTL) |= (1 << 16);
225 printk_debug("Loading port arbitration table ...");
226 /* Loop until bit 0 becomes 0 */
228 while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) ;
230 printk_debug("timeout!\n");
232 printk_debug("ok\n");
235 EPBAR32(EPVC1RCTL) |= (1 << 31);
237 printk_debug("Wait for VC1 negotiation ...");
238 /* Wait for VC1 negotiation pending */
240 while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) ;
242 printk_debug("timeout!\n");
244 printk_debug("ok\n");
248 static void ich7_setup_dmi_rcrb(void)
253 reg16 = RCBA16(LCTL);
256 RCBA16(LCTL) = reg16;
258 RCBA32(V0CTL) = 0x80000001;
259 RCBA32(V1CAP) = 0x03128010;
260 RCBA32(ESD) = 0x00000810;
261 RCBA32(RP1D) = 0x01000003;
262 RCBA32(RP2D) = 0x02000002;
263 RCBA32(RP3D) = 0x03000002;
264 RCBA32(RP4D) = 0x04000002;
265 RCBA32(HDD) = 0x0f000003;
266 RCBA32(RP5D) = 0x05000002;
268 RCBA32(RPFN) = 0x00543210;
270 pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
271 pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
272 pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
274 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
275 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
278 static void i945_setup_dmi_rcrb(void)
283 printk_debug("Setting up DMI RCRB\n");
285 /* Virtual Channel 0 Configuration */
286 reg32 = DMIBAR32(DMIVC0RCTL0);
288 DMIBAR32(DMIVC0RCTL0) = reg32;
290 reg32 = DMIBAR32(DMIPVCCAP1);
293 DMIBAR32(DMIPVCCAP1) = reg32;
295 reg32 = DMIBAR32(DMIVC1RCTL);
297 reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
298 DMIBAR32(DMIVC1RCTL) = reg32;
300 reg32 = DMIBAR32(DMIVC1RCTL);
303 DMIBAR32(DMIVC1RCTL) = reg32;
306 DMIBAR32(DMIVC1RCTL) |= (1 << 31);
308 printk_debug("Wait for VC1 negotiation ...");
309 /* Wait for VC1 negotiation pending */
311 while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) ;
313 printk_debug("timeout!\n");
315 printk_debug("done..\n");
317 /* Enable Active State Power Management (ASPM) L0 state */
319 reg32 = DMIBAR32(DMILCAP);
326 DMIBAR32(DMILCAP) = reg32;
328 reg32 = DMIBAR32(DMICC);
332 DMIBAR32(DMICC) = reg32;
335 DMIBAR32(DMILCTL) |= (3 << 0);
339 /* Last but not least, some additional steps */
340 reg32 = MCHBAR32(FSBSNPCTL);
341 reg32 &= ~(0xff << 2);
342 reg32 |= (0xaa << 2);
343 MCHBAR32(FSBSNPCTL) = reg32;
345 DMIBAR32(0x2c) = 0x86000040;
347 reg32 = DMIBAR32(0x204);
350 reg32 |= 0x13f; /* for x4 DMI only */
352 reg32 |= 0x1e4; /* for x2 DMI only */
354 DMIBAR32(0x204) = reg32;
356 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
357 DMIBAR32(0x200) |= (1 << 21);
359 DMIBAR32(0x200) &= ~(1 << 21);
362 reg32 = DMIBAR32(0x204);
363 reg32 &= ~((1 << 11) | (1 << 10));
364 DMIBAR32(0x204) = reg32;
366 reg32 = DMIBAR32(0x204);
367 reg32 &= ~(0xff << 12);
368 reg32 |= (0x0d << 12);
369 DMIBAR32(0x204) = reg32;
371 DMIBAR32(DMICTL1) |= (3 << 24);
373 reg32 = DMIBAR32(0x200);
374 reg32 &= ~(0x3 << 26);
375 reg32 |= (0x02 << 26);
376 DMIBAR32(0x200) = reg32;
378 DMIBAR32(DMIDRCCFG) &= ~(1 << 31);
379 DMIBAR32(DMICTL2) |= (1 << 31);
381 if (i945_silicon_revision() >= 3) {
382 reg32 = DMIBAR32(0xec0);
385 DMIBAR32(0xec0) = reg32;
387 reg32 = DMIBAR32(0xed4);
390 DMIBAR32(0xed4) = reg32;
392 reg32 = DMIBAR32(0xee8);
395 DMIBAR32(0xee8) = reg32;
397 reg32 = DMIBAR32(0xefc);
400 DMIBAR32(0xefc) = reg32;
403 /* wait for bit toggle to 0 */
404 printk_debug("Waiting for DMI hardware...");
406 while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) ;
408 printk_debug("timeout!\n");
410 printk_debug("ok\n");
412 DMIBAR32(0x1c4) = 0xffffffff;
413 DMIBAR32(0x1d0) = 0xffffffff;
414 DMIBAR32(0x228) = 0xffffffff;
416 DMIBAR32(0x308) = DMIBAR32(0x308);
417 DMIBAR32(0x314) = DMIBAR32(0x314);
418 DMIBAR32(0x324) = DMIBAR32(0x324);
419 DMIBAR32(0x328) = DMIBAR32(0x328);
420 DMIBAR32(0x338) = DMIBAR32(0x334);
421 DMIBAR32(0x338) = DMIBAR32(0x338);
423 if (i945_silicon_revision() == 1 && ((MCHBAR8(0xe08) & (1 << 5)) == 1)) {
424 if ((MCHBAR32(0x214) & 0xf) != 0x3) {
426 ("DMI link requires A1 stepping workaround. Rebooting.\n");
427 reg32 = MCHBAR32(MMARB1);
431 for (;;) ; /* wait for reset */
436 static void i945_setup_pci_express_x16(void)
442 /* For now we just disable the x16 link */
443 printk_debug("Disabling PCI Express x16 Link\n");
445 MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0);
447 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
449 pcie_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
451 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
453 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
455 reg16 = pcie_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1);
457 pcie_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16);
459 printk_debug("Wait for link to enter detect state... ");
461 for (reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
462 (reg32 & 0x000f0000) && --timeout;) ;
464 printk_debug("timeout!\n");
466 printk_debug("ok\n");
468 /* Finally: Disable the PCI config header */
469 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
470 reg16 &= ~DEVEN_D1F0;
471 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
474 static void i945_setup_root_complex_topology(void)
478 printk_debug("Setting up Root Complex Topology\n");
479 /* Egress Port Root Topology */
480 reg32 = EPBAR32(EPESD);
483 EPBAR32(EPESD) = reg32;
485 EPBAR32(EPLE1D) |= (1 << 0);
487 EPBAR32(EPLE1A) = DEFAULT_PCIEXBAR + 0x4000;
489 EPBAR32(EPLE2D) |= (1 << 0);
491 /* DMI Port Root Topology */
492 reg32 = DMIBAR32(DMILE1D);
494 DMIBAR32(DMILE1D) = reg32;
496 reg32 = DMIBAR32(DMILE1D);
499 DMIBAR32(DMILE1D) = reg32;
501 DMIBAR32(DMILE1D) |= (1 << 0);
503 DMIBAR32(DMILE1A) = DEFAULT_PCIEXBAR + 0x8000;
505 DMIBAR32(DMILE2D) |= (1 << 0);
507 DMIBAR32(DMILE2A) = DEFAULT_PCIEXBAR + 0x5000;
509 /* PCI Express x16 Port Root Topology */
510 if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) {
511 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x158,
512 DEFAULT_PCIEXBAR + 0x5000);
514 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x150);
516 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32);
520 static void ich7_setup_root_complex_topology(void)
522 RCBA32(0x104) = 0x00000802;
523 RCBA32(0x110) = 0x00000001;
524 RCBA32(0x114) = 0x00000000;
525 RCBA32(0x118) = 0x00000000;
528 static void ich7_setup_pci_express(void)
530 RCBA32(CG) |= (1 << 0);
532 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
534 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
537 static void i945_early_initialization(void)
539 /* Print some chipset specific information */
540 i945_detect_chipset();
542 /* Setup all BARs required for early PCIe and raminit */
545 /* Change port80 to LPC */
546 RCBA32(GCS) &= (~0x04);
549 static void i945_late_initialization(void)
551 i945_setup_egress_port();
553 ich7_setup_root_complex_topology();
555 ich7_setup_pci_express();
557 ich7_setup_dmi_rcrb();
559 i945_setup_dmi_rcrb();
561 i945_setup_pci_express_x16();
563 i945_setup_root_complex_topology();