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), 8);
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\r\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.\r\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.\r\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.\r\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_config8(PCI_DEV(0, 0x00, 0), TOLUD, 0x40); /* 1G XXX dynamic! */
140 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
141 printk_debug(" done.\r\n");
143 /* Wait for MCH BAR to come up */
144 printk_debug("Waiting for MCHBAR to come up...");
145 if ((pci_read_config8(PCI_DEV(0, 0x0f, 0), 0xe6) & 0x2) == 0x00) { /* Bit 49 of CAPID0 */
147 reg8 = *(volatile u8 *)0xfed40000;
148 } while (!(reg8 & 0x80));
150 printk_debug("ok\r\n");
153 static void i945_setup_egress_port(void)
158 printk_debug("Setting up Egress Port RCRB\n");
160 /* Egress Port Virtual Channel 0 Configuration */
162 /* map only TC0 to VC0 */
163 reg32 = EPBAR32(EPVC0RCTL);
165 EPBAR32(EPVC0RCTL) = reg32;
168 reg32 = EPBAR32(EPPVCCAP1);
171 EPBAR32(EPPVCCAP1) = reg32;
173 /* Egress Port Virtual Channel 1 Configuration */
174 reg32 = EPBAR32(0x2c);
176 if ((MCHBAR32(CLKCFG) & 7) == 1)
177 reg32 |= 0x0d; /* 533MHz */
178 if ((MCHBAR32(CLKCFG) & 7) == 3)
179 reg32 |= 0x10; /* 667MHz */
180 EPBAR32(0x2c) = reg32;
182 EPBAR32(EPVC1MTS) = 0x0a0a0a0a;
184 reg32 = EPBAR32(EPVC1RCAP);
185 reg32 &= ~(0x7f << 16);
186 reg32 |= (0x0a << 16);
187 EPBAR32(EPVC1RCAP) = reg32;
189 if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */
190 EPBAR32(EPVC1IST + 0) = 0x009c009c;
191 EPBAR32(EPVC1IST + 4) = 0x009c009c;
194 if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */
195 EPBAR32(EPVC1IST + 0) = 0x00c000c0;
196 EPBAR32(EPVC1IST + 4) = 0x00c000c0;
199 /* Is internal graphics enabled? */
200 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
201 MCHBAR32(MMARB1) |= (1 << 17);
204 /* Assign Virtual Channel ID 1 to VC1 */
205 reg32 = EPBAR32(EPVC1RCTL);
208 EPBAR32(EPVC1RCTL) = reg32;
210 reg32 = EPBAR32(EPVC1RCTL);
213 EPBAR32(EPVC1RCTL) = reg32;
215 EPBAR32(PORTARB + 0x00) = 0x01000001;
216 EPBAR32(PORTARB + 0x04) = 0x00040000;
217 EPBAR32(PORTARB + 0x08) = 0x00001000;
218 EPBAR32(PORTARB + 0x0c) = 0x00000040;
219 EPBAR32(PORTARB + 0x10) = 0x01000001;
220 EPBAR32(PORTARB + 0x14) = 0x00040000;
221 EPBAR32(PORTARB + 0x18) = 0x00001000;
222 EPBAR32(PORTARB + 0x1c) = 0x00000040;
224 EPBAR32(EPVC1RCTL) |= (1 << 16);
225 EPBAR32(EPVC1RCTL) |= (1 << 16);
227 printk_debug("Loading port arbitration table ...");
228 /* Loop until bit 0 becomes 0 */
230 while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) ;
232 printk_debug("timeout!\n");
234 printk_debug("ok\n");
237 EPBAR32(EPVC1RCTL) |= (1 << 31);
239 printk_debug("Wait for VC1 negotiation ...");
240 /* Wait for VC1 negotiation pending */
242 while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) ;
244 printk_debug("timeout!\n");
246 printk_debug("ok\n");
250 static void ich7_setup_dmi_rcrb(void)
255 reg16 = RCBA16(LCTL);
258 RCBA16(LCTL) = reg16;
260 RCBA32(V0CTL) = 0x80000001;
261 RCBA32(V1CAP) = 0x03128010;
262 RCBA32(ESD) = 0x00000810;
263 RCBA32(RP1D) = 0x01000003;
264 RCBA32(RP2D) = 0x02000002;
265 RCBA32(RP3D) = 0x03000002;
266 RCBA32(RP4D) = 0x04000002;
267 RCBA32(HDD) = 0x0f000003;
268 RCBA32(RP5D) = 0x05000002;
270 RCBA32(RPFN) = 0x00543210;
272 pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
273 pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
274 pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
276 pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
277 pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
280 static void i945_setup_dmi_rcrb(void)
285 printk_debug("Setting up DMI RCRB\n");
287 /* Virtual Channel 0 Configuration */
288 reg32 = DMIBAR32(DMIVC0RCTL0);
290 DMIBAR32(DMIVC0RCTL0) = reg32;
292 reg32 = DMIBAR32(DMIPVCCAP1);
295 DMIBAR32(DMIPVCCAP1) = reg32;
297 reg32 = DMIBAR32(DMIVC1RCTL);
299 reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
300 DMIBAR32(DMIVC1RCTL) = reg32;
302 reg32 = DMIBAR32(DMIVC1RCTL);
305 DMIBAR32(DMIVC1RCTL) = reg32;
308 DMIBAR32(DMIVC1RCTL) |= (1 << 31);
310 printk_debug("Wait for VC1 negotiation ...");
311 /* Wait for VC1 negotiation pending */
313 while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) ;
315 printk_debug("timeout!\n");
317 printk_debug("done..\n");
319 /* Enable Active State Power Management (ASPM) L0 state */
321 reg32 = DMIBAR32(DMILCAP);
328 DMIBAR32(DMILCAP) = reg32;
330 reg32 = DMIBAR32(DMICC);
334 DMIBAR32(DMICC) = reg32;
337 DMIBAR32(DMILCTL) |= (3 << 0);
341 /* Last but not least, some additional steps */
342 reg32 = MCHBAR32(FSBSNPCTL);
343 reg32 &= ~(0xff << 2);
344 reg32 |= (0xaa << 2);
345 MCHBAR32(FSBSNPCTL) = reg32;
347 DMIBAR32(0x2c) = 0x86000040;
349 reg32 = DMIBAR32(0x204);
352 reg32 |= 0x13f; /* for x4 DMI only */
354 reg32 |= 0x1e4; /* for x2 DMI only */
356 DMIBAR32(0x204) = reg32;
358 if (pci_read_config8(PCI_DEV(0, 0x0, 0), 54) & ((1 << 4) | (1 << 3))) { /* DEVEN */
359 DMIBAR32(0x200) |= (1 << 21);
361 DMIBAR32(0x200) &= ~(1 << 21);
364 reg32 = DMIBAR32(0x204);
365 reg32 &= ~((1 << 11) | (1 << 10));
366 DMIBAR32(0x204) = reg32;
368 reg32 = DMIBAR32(0x204);
369 reg32 &= ~(0xff << 12);
370 reg32 |= (0x0d << 12);
371 DMIBAR32(0x204) = reg32;
373 DMIBAR32(DMICTL1) |= (3 << 24);
375 reg32 = DMIBAR32(0x200);
376 reg32 &= ~(0x3 << 26);
377 reg32 |= (0x02 << 26);
378 DMIBAR32(0x200) = reg32;
380 DMIBAR32(DMIDRCCFG) &= ~(1 << 31);
381 DMIBAR32(DMICTL2) |= (1 << 31);
383 if (i945_silicon_revision() >= 3) {
384 reg32 = DMIBAR32(0xec0);
387 DMIBAR32(0xec0) = reg32;
389 reg32 = DMIBAR32(0xed4);
392 DMIBAR32(0xed4) = reg32;
394 reg32 = DMIBAR32(0xee8);
397 DMIBAR32(0xee8) = reg32;
399 reg32 = DMIBAR32(0xefc);
402 DMIBAR32(0xefc) = reg32;
405 /* wait for bit toggle to 0 */
406 printk_debug("Waiting for DMI hardware...");
408 while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) ;
410 printk_debug("timeout!\n");
412 printk_debug("ok\n");
414 DMIBAR32(0x1c4) = 0xffffffff;
415 DMIBAR32(0x1d0) = 0xffffffff;
416 DMIBAR32(0x228) = 0xffffffff;
418 DMIBAR32(0x308) = DMIBAR32(0x308);
419 DMIBAR32(0x314) = DMIBAR32(0x314);
420 DMIBAR32(0x324) = DMIBAR32(0x324);
421 DMIBAR32(0x328) = DMIBAR32(0x328);
422 DMIBAR32(0x338) = DMIBAR32(0x334);
423 DMIBAR32(0x338) = DMIBAR32(0x338);
425 if (i945_silicon_revision() == 1 && ((MCHBAR8(0xe08) & (1 << 5)) == 1)) {
426 if ((MCHBAR32(0x214) & 0xf) != 0x3) {
428 ("DMI link requires A1 stepping workaround. Rebooting.\n");
429 reg32 = MCHBAR32(MMARB1);
433 for (;;) ; /* wait for reset */
438 static void i945_setup_pci_express_x16(void)
445 /* For now we just disable the x16 link */
446 printk_debug("Disabling PCI Express x16 Link\n");
448 MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0);
450 reg8 = pcie_read_config8(PCI_DEV(0, 0x01, 0), BCTRL1);
452 pcie_write_config8(PCI_DEV(0, 0x01, 0), BCTRL1, reg8);
454 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x224);
456 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32);
458 reg8 = pcie_read_config8(PCI_DEV(0, 0x01, 0), BCTRL1);
460 pcie_write_config8(PCI_DEV(0, 0x01, 0), BCTRL1, reg8);
462 printk_debug("Wait for link to enter detect state... ");
464 for (reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x214);
465 (reg32 & 0x000f0000) && --timeout;) ;
467 printk_debug("timeout!\n");
469 printk_debug("ok\n");
471 /* Finally: Disable the PCI config header */
472 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN);
473 reg16 &= ~DEVEN_D1F0;
474 pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16);
477 static void i945_setup_root_complex_topology(void)
481 printk_debug("Setting up Root Complex Topology\n");
482 /* Egress Port Root Topology */
483 reg32 = EPBAR32(EPESD);
486 EPBAR32(EPESD) = reg32;
488 EPBAR32(EPLE1D) |= (1 << 0);
490 EPBAR32(EPLE1A) = DEFAULT_PCIEXBAR + 0x4000;
492 EPBAR32(EPLE2D) |= (1 << 0);
494 /* DMI Port Root Topology */
495 reg32 = DMIBAR32(DMILE1D);
497 DMIBAR32(DMILE1D) = reg32;
499 reg32 = DMIBAR32(DMILE1D);
502 DMIBAR32(DMILE1D) = reg32;
504 DMIBAR32(DMILE1D) |= (1 << 0);
506 DMIBAR32(DMILE1A) = DEFAULT_PCIEXBAR + 0x8000;
508 DMIBAR32(DMILE2D) |= (1 << 0);
510 DMIBAR32(DMILE2A) = DEFAULT_PCIEXBAR + 0x5000;
512 /* PCI Express x16 Port Root Topology */
513 if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) {
514 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x158,
515 DEFAULT_PCIEXBAR + 0x5000);
517 reg32 = pcie_read_config32(PCI_DEV(0, 0x01, 0), 0x150);
519 pcie_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32);
523 static void ich7_setup_root_complex_topology(void)
525 RCBA32(0x104) = 0x00000802;
526 RCBA32(0x110) = 0x00000001;
527 RCBA32(0x114) = 0x00000000;
528 RCBA32(0x118) = 0x00000000;
531 static void ich7_setup_pci_express(void)
533 RCBA32(CG) |= (1 << 0);
535 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
537 pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
540 static void i945_early_initialization(void)
542 /* Print some chipset specific information */
543 i945_detect_chipset();
545 /* Setup all BARs required for early PCIe and raminit */
548 /* Change port80 to LPC */
549 RCBA32(GCS) &= (~0x04);
552 static void i945_late_initialization(void)
554 i945_setup_egress_port();
556 ich7_setup_root_complex_topology();
558 ich7_setup_pci_express();
560 ich7_setup_dmi_rcrb();
562 i945_setup_dmi_rcrb();
564 i945_setup_pci_express_x16();
566 i945_setup_root_complex_topology();