coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
early_init.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <cbmem.h>
4 #include <cf9_reset.h>
5 #include <console/console.h>
6 #include <device/pci_def.h>
7 #include <device/pci_ops.h>
8 #include <device/pci.h>
9 #include <option.h>
10 #include <romstage_handoff.h>
11 #include <types.h>
12 
13 #include "i945.h"
14 
16 {
18 }
19 
20 static void i945m_detect_chipset(void)
21 {
22  u8 reg8;
23 
24  printk(BIOS_INFO, "\n");
25  reg8 = (pci_read_config8(HOST_BRIDGE, 0xe7) & 0x70) >> 4;
26  switch (reg8) {
27  case 1:
28  printk(BIOS_INFO, "Mobile Intel(R) 82945GM/GME Express");
29  break;
30  case 2:
31  printk(BIOS_INFO, "Mobile Intel(R) 82945GMS/GU/GSE Express");
32  break;
33  case 3:
34  printk(BIOS_INFO, "Mobile Intel(R) 82945PM Express");
35  break;
36  case 5:
37  printk(BIOS_INFO, "Intel(R) 82945GT Express");
38  break;
39  case 6:
40  printk(BIOS_INFO, "Mobile Intel(R) 82943/82940GML Express");
41  break;
42  default: /* Others reserved. */
43  printk(BIOS_INFO, "Unknown (%02x)", reg8);
44  }
45  printk(BIOS_INFO, " Chipset\n");
46 
47  printk(BIOS_DEBUG, "(G)MCH capable of up to FSB ");
48  reg8 = (pci_read_config8(HOST_BRIDGE, 0xe3) & 0xe0) >> 5;
49  switch (reg8) {
50  case 2:
51  printk(BIOS_DEBUG, "800 MHz"); /* According to 965 spec */
52  break;
53  case 3:
54  printk(BIOS_DEBUG, "667 MHz");
55  break;
56  case 4:
57  printk(BIOS_DEBUG, "533 MHz");
58  break;
59  default:
60  printk(BIOS_DEBUG, "N/A MHz (%02x)", reg8);
61  }
62  printk(BIOS_DEBUG, "\n");
63 
64  printk(BIOS_DEBUG, "(G)MCH capable of ");
65  reg8 = (pci_read_config8(HOST_BRIDGE, 0xe4) & 0x07);
66  switch (reg8) {
67  case 2:
68  printk(BIOS_DEBUG, "up to DDR2-667");
69  break;
70  case 3:
71  printk(BIOS_DEBUG, "up to DDR2-533");
72  break;
73  case 4:
74  printk(BIOS_DEBUG, "DDR2-400");
75  break;
76  default: /* Others reserved. */
77  printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8);
78  }
79  printk(BIOS_DEBUG, "\n");
80 
81  if (CONFIG(NORTHBRIDGE_INTEL_SUBTYPE_I945GC))
82  printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
83 }
84 
85 static void i945_detect_chipset(void)
86 {
87  u8 reg8;
88 
89  printk(BIOS_INFO, "\nIntel(R) ");
90 
91  reg8 = ((pci_read_config8(HOST_BRIDGE, 0xe7) >> 5) & 4)
92  | ((pci_read_config8(HOST_BRIDGE, 0xe4) >> 4) & 3);
93  switch (reg8) {
94  case 0:
95  case 1:
96  printk(BIOS_INFO, "82945G");
97  break;
98  case 2:
99  case 3:
100  printk(BIOS_INFO, "82945P");
101  break;
102  case 4:
103  printk(BIOS_INFO, "82945GC");
104  break;
105  case 5:
106  printk(BIOS_INFO, "82945GZ");
107  break;
108  case 6:
109  case 7:
110  printk(BIOS_INFO, "82945PL");
111  break;
112  default:
113  break;
114  }
115  printk(BIOS_INFO, " Chipset\n");
116 
117  printk(BIOS_DEBUG, "(G)MCH capable of ");
118  reg8 = (pci_read_config8(HOST_BRIDGE, 0xe4) & 0x07);
119  switch (reg8) {
120  case 0:
121  case 2:
122  printk(BIOS_DEBUG, "up to DDR2-667");
123  break;
124  case 3:
125  printk(BIOS_DEBUG, "up to DDR2-533");
126  break;
127  default: /* Others reserved. */
128  printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8);
129  }
130  printk(BIOS_DEBUG, "\n");
131 
132  if (CONFIG(NORTHBRIDGE_INTEL_SUBTYPE_I945GM))
133  printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n");
134 }
135 
136 static void i945_setup_bars(void)
137 {
138  u8 reg8, gfxsize;
139 
140  /* As of now, we don't have all the A0 workarounds implemented */
141  if (i945_silicon_revision() == 0)
142  printk(BIOS_INFO, "Warning: i945 silicon revision A0 might not work correctly.\n");
143 
144  printk(BIOS_DEBUG, "Setting up static northbridge registers...");
145  /* Set up all hardcoded northbridge BARs */
146  pci_write_config32(HOST_BRIDGE, EPBAR, CONFIG_FIXED_EPBAR_MMIO_BASE | 1);
147  pci_write_config32(HOST_BRIDGE, MCHBAR, CONFIG_FIXED_MCHBAR_MMIO_BASE | 1);
148  pci_write_config32(HOST_BRIDGE, DMIBAR, CONFIG_FIXED_DMIBAR_MMIO_BASE | 1);
150 
151  /* vram size from CMOS option */
152  gfxsize = get_uint_option("gfx_uma_size", 2); /* 2 for 8MB */
153  /* make sure no invalid setting is used */
154  if (gfxsize > 6)
155  gfxsize = 2;
156  pci_write_config16(HOST_BRIDGE, GGC, ((gfxsize + 1) << 4));
157  /* TSEG 2M, This amount can easily be covered by SMRR MTRR's,
158  which requires to have TSEG_BASE aligned to TSEG_SIZE. */
159  pci_update_config8(HOST_BRIDGE, ESMRAMC, ~0x07, (1 << 1) | (1 << 0));
160 
161  /* Set C0000-FFFFF to access RAM on both reads and writes */
169 
170  printk(BIOS_DEBUG, " done.\n");
171 
172  /* Wait for MCH BAR to come up */
173  printk(BIOS_DEBUG, "Waiting for MCHBAR to come up...");
174  if ((pci_read_config32(HOST_BRIDGE, 0xe4) & 0x20000) == 0x00) { /* Bit 49 of CAPID0 */
175  do {
176  reg8 = *(volatile u8 *)0xfed40000;
177  } while (!(reg8 & 0x80));
178  }
179  printk(BIOS_DEBUG, "ok\n");
180 }
181 
182 static void i945_setup_egress_port(void)
183 {
184  u32 reg32;
185  u32 timeout;
186 
187  printk(BIOS_DEBUG, "Setting up Egress Port RCRB\n");
188 
189  /* Egress Port Virtual Channel 0 Configuration */
190 
191  /* map only TC0 to VC0 */
192  reg32 = epbar_read32(EPVC0RCTL);
193  reg32 &= 0xffffff01;
194  epbar_write32(EPVC0RCTL, reg32);
195 
196  reg32 = epbar_read32(EPPVCCAP1);
197  reg32 &= ~(7 << 0);
198  reg32 |= 1;
199  epbar_write32(EPPVCCAP1, reg32);
200 
201  /* Egress Port Virtual Channel 1 Configuration */
202  reg32 = epbar_read32(0x2c);
203  reg32 &= 0xffffff00;
204  if (CONFIG(NORTHBRIDGE_INTEL_SUBTYPE_I945GC)) {
205  if ((mchbar_read32(CLKCFG) & 7) == 0)
206  reg32 |= 0x1a; /* 1067MHz */
207  }
208  if ((mchbar_read32(CLKCFG) & 7) == 1)
209  reg32 |= 0x0d; /* 533MHz */
210  if ((mchbar_read32(CLKCFG) & 7) == 2)
211  reg32 |= 0x14; /* 800MHz */
212  if ((mchbar_read32(CLKCFG) & 7) == 3)
213  reg32 |= 0x10; /* 667MHz */
214  epbar_write32(0x2c, reg32);
215 
216  epbar_write32(EPVC1MTS, 0x0a0a0a0a);
217 
218  reg32 = epbar_read32(EPVC1RCAP);
219  reg32 &= ~(0x7f << 16);
220  reg32 |= (0x0a << 16);
221  epbar_write32(EPVC1RCAP, reg32);
222 
223  if (CONFIG(NORTHBRIDGE_INTEL_SUBTYPE_I945GC)) {
224  if ((mchbar_read32(CLKCFG) & 7) == 0) { /* 1067MHz */
225  epbar_write32(EPVC1IST + 0, 0x01380138);
226  epbar_write32(EPVC1IST + 4, 0x01380138);
227  }
228  }
229 
230  if ((mchbar_read32(CLKCFG) & 7) == 1) { /* 533MHz */
231  epbar_write32(EPVC1IST + 0, 0x009c009c);
232  epbar_write32(EPVC1IST + 4, 0x009c009c);
233  }
234 
235  if ((mchbar_read32(CLKCFG) & 7) == 2) { /* 800MHz */
236  epbar_write32(EPVC1IST + 0, 0x00f000f0);
237  epbar_write32(EPVC1IST + 4, 0x00f000f0);
238  }
239 
240  if ((mchbar_read32(CLKCFG) & 7) == 3) { /* 667MHz */
241  epbar_write32(EPVC1IST + 0, 0x00c000c0);
242  epbar_write32(EPVC1IST + 4, 0x00c000c0);
243  }
244 
245  /* Is internal graphics enabled? */
247  mchbar_setbits32(MMARB1, 1 << 17);
248 
249  /* Assign Virtual Channel ID 1 to VC1 */
250  reg32 = epbar_read32(EPVC1RCTL);
251  reg32 &= ~(7 << 24);
252  reg32 |= (1 << 24);
253  epbar_write32(EPVC1RCTL, reg32);
254 
255  reg32 = epbar_read32(EPVC1RCTL);
256  reg32 &= 0xffffff01;
257  reg32 |= (1 << 7);
258  epbar_write32(EPVC1RCTL, reg32);
259 
260  epbar_write32(PORTARB + 0x00, 0x01000001);
261  epbar_write32(PORTARB + 0x04, 0x00040000);
262  epbar_write32(PORTARB + 0x08, 0x00001000);
263  epbar_write32(PORTARB + 0x0c, 0x00000040);
264  epbar_write32(PORTARB + 0x10, 0x01000001);
265  epbar_write32(PORTARB + 0x14, 0x00040000);
266  epbar_write32(PORTARB + 0x18, 0x00001000);
267  epbar_write32(PORTARB + 0x1c, 0x00000040);
268 
269  epbar_setbits32(EPVC1RCTL, 1 << 16);
270  epbar_setbits32(EPVC1RCTL, 1 << 16);
271 
272  printk(BIOS_DEBUG, "Loading port arbitration table ...");
273  /* Loop until bit 0 becomes 0 */
274  timeout = 0x7fffff;
275  while ((epbar_read16(EPVC1RSTS) & (1 << 0)) && --timeout)
276  ;
277  if (!timeout)
278  printk(BIOS_DEBUG, "timeout!\n");
279  else
280  printk(BIOS_DEBUG, "ok\n");
281 
282  /* Now enable VC1 */
283  epbar_setbits32(EPVC1RCTL, 1 << 31);
284 
285  printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
286  /* Wait for VC1 negotiation pending */
287  timeout = 0x7fff;
288  while ((epbar_read16(EPVC1RSTS) & (1 << 1)) && --timeout)
289  ;
290  if (!timeout)
291  printk(BIOS_DEBUG, "timeout!\n");
292  else
293  printk(BIOS_DEBUG, "ok\n");
294 
295 }
296 
297 static void ich7_setup_dmi_rcrb(void)
298 {
299  u16 reg16;
300  u32 reg32;
301 
302  reg16 = RCBA16(LCTL);
303  reg16 &= ~(3 << 0);
304  reg16 |= 3;
305  RCBA16(LCTL) = reg16;
306 
307  RCBA32(V0CTL) = 0x80000001;
308  RCBA32(V1CAP) = 0x03128010;
309 
310  pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141);
311  pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141);
312  pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141);
313 
314  pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0);
315  pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0);
316 
317  reg32 = RCBA32(V1CTL);
318  reg32 &= ~((0x7f << 1) | (7 << 17) | (7 << 24));
319  reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31);
320  RCBA32(V1CTL) = reg32;
321 
322  RCBA32(LCAP) |= (3 << 10);
323 }
324 
325 static void i945_setup_dmi_rcrb(void)
326 {
327  u32 reg32;
328  u32 timeout;
329  int activate_aspm = 1; /* hardcode ASPM for now */
330 
331  printk(BIOS_DEBUG, "Setting up DMI RCRB\n");
332 
333  /* Virtual Channel 0 Configuration */
334  reg32 = dmibar_read32(DMIVC0RCTL0);
335  reg32 &= 0xffffff01;
336  dmibar_write32(DMIVC0RCTL0, reg32);
337 
338  reg32 = dmibar_read32(DMIPVCCAP1);
339  reg32 &= ~(7 << 0);
340  reg32 |= 1;
341  dmibar_write32(DMIPVCCAP1, reg32);
342 
343  reg32 = dmibar_read32(DMIVC1RCTL);
344  reg32 &= ~(7 << 24);
345  reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */
346  dmibar_write32(DMIVC1RCTL, reg32);
347 
348  reg32 = dmibar_read32(DMIVC1RCTL);
349  reg32 &= 0xffffff01;
350  reg32 |= (1 << 7);
351  dmibar_write32(DMIVC1RCTL, reg32);
352 
353  /* Now enable VC1 */
354  dmibar_setbits32(DMIVC1RCTL, 1 << 31);
355 
356  printk(BIOS_DEBUG, "Wait for VC1 negotiation ...");
357  /* Wait for VC1 negotiation pending */
358  timeout = 0x7ffff;
359  while ((dmibar_read16(DMIVC1RSTS) & (1 << 1)) && --timeout)
360  ;
361  if (!timeout)
362  printk(BIOS_DEBUG, "timeout!\n");
363  else
364  printk(BIOS_DEBUG, "done..\n");
365 
366  /* Enable Active State Power Management (ASPM) L0 state */
367 
368  reg32 = dmibar_read32(DMILCAP);
369  reg32 &= ~(7 << 12);
370  reg32 |= (2 << 12);
371 
372  reg32 &= ~(7 << 15);
373 
374  reg32 |= (2 << 15);
375  dmibar_write32(DMILCAP, reg32);
376 
377  reg32 = dmibar_read32(DMICC);
378  reg32 &= 0x00ffffff;
379  reg32 &= ~(3 << 0);
380  reg32 |= (1 << 0);
381  reg32 &= ~(3 << 20);
382  reg32 |= (1 << 20);
383 
384  dmibar_write32(DMICC, reg32);
385 
386  if (activate_aspm)
387  dmibar_setbits32(DMILCTL, 3 << 0);
388 
389  /* Last but not least, some additional steps */
390  reg32 = mchbar_read32(FSBSNPCTL);
391  reg32 &= ~(0xff << 2);
392  reg32 |= (0xaa << 2);
393  mchbar_write32(FSBSNPCTL, reg32);
394 
395  dmibar_write32(0x2c, 0x86000040);
396 
397  reg32 = dmibar_read32(0x204);
398  reg32 &= ~0x3ff;
399 #if 1
400  reg32 |= 0x13f; /* for x4 DMI only */
401 #else
402  reg32 |= 0x1e4; /* for x2 DMI only */
403 #endif
404  dmibar_write32(0x204, reg32);
405 
407  printk(BIOS_DEBUG, "Internal graphics: enabled\n");
408  dmibar_setbits32(0x200, 1 << 21);
409  } else {
410  printk(BIOS_DEBUG, "Internal graphics: disabled\n");
411  dmibar_clrbits32(0x200, 1 << 21);
412  }
413 
414  reg32 = dmibar_read32(0x204);
415  reg32 &= ~((1 << 11) | (1 << 10));
416  dmibar_write32(0x204, reg32);
417 
418  reg32 = dmibar_read32(0x204);
419  reg32 &= ~(0xff << 12);
420  reg32 |= (0x0d << 12);
421  dmibar_write32(0x204, reg32);
422 
423  dmibar_setbits32(DMICTL1, 3 << 24);
424 
425  reg32 = dmibar_read32(0x200);
426  reg32 &= ~(0x3 << 26);
427  reg32 |= (0x02 << 26);
428  dmibar_write32(0x200, reg32);
429 
430  dmibar_clrbits32(DMIDRCCFG, 1 << 31);
431  dmibar_setbits32(DMICTL2, 1 << 31);
432 
433  if (i945_silicon_revision() >= 3) {
434  reg32 = dmibar_read32(0xec0);
435  reg32 &= 0x0fffffff;
436  reg32 |= (2 << 28);
437  dmibar_write32(0xec0, reg32);
438 
439  reg32 = dmibar_read32(0xed4);
440  reg32 &= 0x0fffffff;
441  reg32 |= (2 << 28);
442  dmibar_write32(0xed4, reg32);
443 
444  reg32 = dmibar_read32(0xee8);
445  reg32 &= 0x0fffffff;
446  reg32 |= (2 << 28);
447  dmibar_write32(0xee8, reg32);
448 
449  reg32 = dmibar_read32(0xefc);
450  reg32 &= 0x0fffffff;
451  reg32 |= (2 << 28);
452  dmibar_write32(0xefc, reg32);
453  }
454 
455  /* wait for bit toggle to 0 */
456  printk(BIOS_DEBUG, "Waiting for DMI hardware...");
457  timeout = 0x7fffff;
458  while ((dmibar_read8(0x32) & (1 << 1)) && --timeout)
459  ;
460  if (!timeout)
461  printk(BIOS_DEBUG, "timeout!\n");
462  else
463  printk(BIOS_DEBUG, "ok\n");
464 
465  /* Clear Error Status Bits! */
466  dmibar_write32(0x1c4, 0xffffffff);
467  dmibar_write32(0x1d0, 0xffffffff);
468  dmibar_write32(0x228, 0xffffffff);
469 
470  /* Program Read-Only Write-Once Registers */
471  dmibar_setbits32(0x308, 0);
472  dmibar_setbits32(0x314, 0);
473  dmibar_setbits32(0x324, 0);
474  dmibar_setbits32(0x328, 0);
475  dmibar_setbits32(0x334, 0);
476  dmibar_setbits32(0x338, 0);
477 
478  if (i945_silicon_revision() == 1 && (mchbar_read8(DFT_STRAP1) & (1 << 5))) {
479  if ((mchbar_read32(0x214) & 0xf) != 0x3) {
480  printk(BIOS_INFO, "DMI link requires A1 stepping workaround. Rebooting.\n");
481  reg32 = dmibar_read32(0x224);
482  reg32 &= ~(7 << 0);
483  reg32 |= (3 << 0);
484  dmibar_write32(0x224, reg32);
485  system_reset();
486  }
487  }
488 }
489 
490 static void i945_setup_pci_express_x16(void)
491 {
492  u32 timeout;
493  u32 reg32;
494  u16 reg16;
495  const pci_devfn_t p2peg = PCI_DEV(0, 0x01, 0);
496 
497  u8 tmp_secondary = 0x0a;
498  const pci_devfn_t peg_plugin = PCI_DEV(tmp_secondary, 0, 0);
499 
500  printk(BIOS_DEBUG, "Enabling PCI Express x16 Link\n");
501 
503 
504  pci_and_config32(p2peg, PEGCC, ~(1 << 8));
505 
506  /* We have no success with querying the usual PCIe registers
507  * for link setup success on the i945. Hence we assign a temporary
508  * PCI bus 0x0a and check whether we find a device on 0:a.0
509  */
510 
511  /* Force PCIRST# */
514 
515  reg16 = pci_read_config16(p2peg, SLOTSTS);
516  printk(BIOS_DEBUG, "SLOTSTS: %04x\n", reg16);
517  if (!(reg16 & 0x48))
518  goto disable_pciexpress_x16_link;
519  reg16 |= (1 << 4) | (1 << 0);
520  pci_write_config16(p2peg, SLOTSTS, reg16);
521 
522  pci_s_bridge_set_secondary(p2peg, tmp_secondary);
523 
524  pci_and_config32(p2peg, 0x224, ~(1 << 8));
525 
526  mchbar_clrbits16(UPMC1, 1 << 5 | 1 << 0);
527 
528  /* Initialize PEG_CAP */
529  pci_or_config16(p2peg, PEG_CAP, 1 << 8);
530 
531  /* Setup SLOTCAP */
532  /* TODO: These values are mainboard dependent and should be set from devicetree.cb.
533  */
534  /* NOTE: SLOTCAP becomes RO after the first write! */
535  reg32 = pci_read_config32(p2peg, SLOTCAP);
536  reg32 &= 0x0007ffff;
537 
538  reg32 &= 0xfffe007f;
539 
540  pci_write_config32(p2peg, SLOTCAP, reg32);
541 
542  /* Wait for training to succeed */
543  printk(BIOS_DEBUG, "PCIe link training ...");
544  timeout = 0x7ffff;
545  while ((((pci_read_config32(p2peg, PEGSTS) >> 16) & 3) != 3) && --timeout)
546  ;
547 
548  reg32 = pci_read_config32(peg_plugin, PCI_VENDOR_ID);
549  if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
550  printk(BIOS_DEBUG, " Detected PCIe device %04x:%04x\n",
551  reg32 & 0xffff, reg32 >> 16);
552  } else {
553  printk(BIOS_DEBUG, " timeout!\n");
554 
555  printk(BIOS_DEBUG, "Restrain PCIe port to x1\n");
556 
557  pci_update_config32(p2peg, PEGSTS, ~(0xf << 1), 1);
558 
559  /* Force PCIRST# */
562 
563  printk(BIOS_DEBUG, "PCIe link training ...");
564  timeout = 0x7ffff;
565  while ((((pci_read_config32(p2peg, PEGSTS) >> 16) & 3) != 3) && --timeout)
566  ;
567 
568  reg32 = pci_read_config32(peg_plugin, PCI_VENDOR_ID);
569  if (reg32 != 0x00000000 && reg32 != 0xffffffff) {
570  printk(BIOS_DEBUG, " Detected PCIe x1 device %04x:%04x\n",
571  reg32 & 0xffff, reg32 >> 16);
572  } else {
573  printk(BIOS_DEBUG, " timeout!\n");
574  printk(BIOS_DEBUG, "Disabling PCIe x16 port completely.\n");
575  goto disable_pciexpress_x16_link;
576  }
577  }
578 
579  reg16 = pci_read_config16(p2peg, 0xb2);
580  reg16 >>= 4;
581  reg16 &= 0x3f;
582  /* reg16 == 1 -> x1; reg16 == 16 -> x16 */
583  printk(BIOS_DEBUG, "PCIe x%d link training succeeded.\n", reg16);
584 
585  reg32 = pci_read_config32(p2peg, PEGTC);
586  reg32 &= 0xfffffc00; /* clear [9:0] */
587  if (reg16 == 1)
588  reg32 |= 0x32b;
589  // TODO
590  /* pci_write_config32(p2peg, PEGTC, reg32); */
591  else if (reg16 == 16)
592  reg32 |= 0x0f4;
593  // TODO
594  /* pci_write_config32(p2peg, PEGTC, reg32); */
595 
596  reg32 = (pci_read_config32(peg_plugin, 0x8) >> 8);
597  printk(BIOS_DEBUG, "PCIe device class: %06x\n", reg32);
598  if (reg32 == 0x030000) {
599  printk(BIOS_DEBUG, "PCIe device is VGA. Disabling IGD.\n");
600  reg16 = (1 << 1);
602 
604  }
605 
606  /* Enable GPEs: PMEGPE, HPGPE, GENGPE */
607  pci_or_config32(p2peg, PEG_LC, (1 << 2) | (1 << 1) | (1 << 0));
608 
609  /* Virtual Channel Configuration: Only VC0 on PCIe x16 */
610  pci_and_config32(p2peg, VC0RCTL, ~0x000000fe);
611 
612  /* Extended VC count */
613  pci_and_config32(p2peg, PVCCAP1, ~(7 << 0));
614 
615  /* Active State Power Management ASPM */
616 
617  /* TODO */
618 
619  /* Clear error bits */
620  pci_write_config16(p2peg, PCISTS1, 0xffff);
621  pci_write_config16(p2peg, SSTS1, 0xffff);
622  pci_write_config16(p2peg, DSTS, 0xffff);
623  pci_write_config32(p2peg, UESTS, 0xffffffff);
624  pci_write_config32(p2peg, CESTS, 0xffffffff);
625  pci_write_config32(p2peg, 0x1f0, 0xffffffff);
626  pci_write_config32(p2peg, 0x228, 0xffffffff);
627 
628  /* Program R/WO registers */
629  pci_update_config32(p2peg, 0x308, ~0, 0);
630  pci_update_config32(p2peg, 0x314, ~0, 0);
631  pci_update_config32(p2peg, 0x324, ~0, 0);
632  pci_update_config32(p2peg, 0x328, ~0, 0);
633 
634  /* Additional PCIe graphics setup */
635  pci_or_config32(p2peg, 0xf0, 3 << 26);
636  pci_or_config32(p2peg, 0xf0, 3 << 24);
637  pci_or_config32(p2peg, 0xf0, 1 << 5);
638 
639  pci_update_config32(p2peg, 0x200, ~(3 << 26), 2 << 26);
640 
641  reg32 = pci_read_config32(p2peg, 0xe80);
642  if (i945_silicon_revision() >= 2)
643  reg32 |= (1 << 12);
644  else
645  reg32 &= ~(1 << 12);
646  pci_write_config32(p2peg, 0xe80, reg32);
647 
648  pci_and_config32(p2peg, 0xeb4, ~(1 << 31));
649 
650  pci_or_config32(p2peg, 0xfc, 1 << 31);
651 
652  if (i945_silicon_revision() >= 3) {
653  static const u32 reglist[] = {
654  0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24, 0xf38, 0xf4c,
655  0xf60, 0xf74, 0xf88, 0xf9c, 0xfb0, 0xfc4, 0xfd8, 0xfec
656  };
657 
658  int i;
659  for (i = 0; i < ARRAY_SIZE(reglist); i++)
660  pci_update_config32(p2peg, reglist[i], ~(0xf << 28), 2 << 28);
661  }
662 
663  if (i945_silicon_revision() <= 2) {
664  /* Set voltage specific parameters */
665  reg32 = pci_read_config32(p2peg, 0xe80);
666  reg32 &= (0xf << 4); /* Default case 1.05V */
667  if ((mchbar_read32(DFT_STRAP1) & (1 << 20)) == 0) { /* 1.50V */
668  reg32 |= (7 << 4);
669  }
670  pci_write_config32(p2peg, 0xe80, reg32);
671  }
672 
673  return;
674 
675 disable_pciexpress_x16_link:
676  /* For now we just disable the x16 link */
677  printk(BIOS_DEBUG, "Disabling PCI Express x16 Link\n");
678 
679  mchbar_setbits16(UPMC1, 1 << 5 | 1 << 0);
680 
681  /* Toggle PCIRST# */
683 
684  pci_or_config32(p2peg, 0x224, 1 << 8);
685 
687 
688  printk(BIOS_DEBUG, "Wait for link to enter detect state... ");
689  timeout = 0x7fffff;
690  for (reg32 = pci_read_config32(p2peg, PEGSTS);
691  (reg32 & 0x000f0000) && --timeout;)
692  ;
693  if (!timeout)
694  printk(BIOS_DEBUG, "timeout!\n");
695  else
696  printk(BIOS_DEBUG, "ok\n");
697 
698  /* Finally: Disable the PCI config header */
700 }
701 
703 {
704  u32 reg32;
705  const pci_devfn_t p2peg = PCI_DEV(0, 0x01, 0);
706 
707  printk(BIOS_DEBUG, "Setting up Root Complex Topology\n");
708  /* Egress Port Root Topology */
709 
710  reg32 = epbar_read32(EPESD);
711  reg32 &= 0xff00ffff;
712  reg32 |= (1 << 16);
713  epbar_write32(EPESD, reg32);
714 
715  epbar_setbits32(EPLE1D, 1 << 16 | 1 << 0);
716 
717  epbar_write32(EPLE1A, CONFIG_FIXED_DMIBAR_MMIO_BASE);
718 
719  epbar_setbits32(EPLE2D, 1 << 16 | 1 << 0);
720 
721  /* DMI Port Root Topology */
722 
723  reg32 = dmibar_read32(DMILE1D);
724  reg32 &= 0x00ffffff;
725 
726  reg32 &= 0xff00ffff;
727  reg32 |= (2 << 16);
728 
729  reg32 |= (1 << 0);
730  dmibar_write32(DMILE1D, reg32);
731 
732  dmibar_write32(DMILE1A, CONFIG_FIXED_RCBA_MMIO_BASE);
733 
734  dmibar_setbits32(DMILE2D, 1 << 16 | 1 << 0);
735 
736  dmibar_write32(DMILE2A, CONFIG_FIXED_EPBAR_MMIO_BASE);
737 
738  /* PCI Express x16 Port Root Topology */
740  pci_write_config32(p2peg, LE1A, CONFIG_FIXED_EPBAR_MMIO_BASE);
741  pci_or_config32(p2peg, LE1D, 1 << 0);
742  }
743 }
744 
746 {
747  /* Write the R/WO registers */
748 
749  RCBA32(ESD) |= (2 << 16);
750 
751  RCBA32(ULD) |= (1 << 24) | (1 << 16);
752 
753  RCBA32(ULBA) = CONFIG_FIXED_DMIBAR_MMIO_BASE;
754  /* Write ESD.CID to TCID */
755  RCBA32(RP1D) |= (2 << 16);
756  RCBA32(RP2D) |= (2 << 16);
757  RCBA32(RP3D) |= (2 << 16);
758  RCBA32(RP4D) |= (2 << 16);
759  RCBA32(HDD) |= (2 << 16);
760  RCBA32(RP5D) |= (2 << 16);
761  RCBA32(RP6D) |= (2 << 16);
762 }
763 
764 static void ich7_setup_pci_express(void)
765 {
766  /* Enable PCIe Root Port Clock Gate */
767  RCBA32(CG) |= (1 << 0);
768 
769  /* Initialize slot power limit for root ports */
770  pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060);
771 
772  pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000);
773 }
774 
776 {
777  /* Print some chipset specific information */
778  switch (pci_read_config32(HOST_BRIDGE, 0)) {
779  case 0x27708086: /* 82945G/GZ/GC/P/PL */
781  break;
782  case 0x27a08086: /* 945GME/GSE */
783  case 0x27ac8086: /* 945GM/PM/GMS/GU/GT, 943/940GML */
785  break;
786  }
787 
788  /* Setup all BARs required for early PCIe and raminit */
789  i945_setup_bars();
790 
791  /* Change port80 to LPC */
792  RCBA32(GCS) &= (~0x04);
793 
794  /* Just do it that way */
795  RCBA32(0x2010) |= (1 << 10);
796 }
797 
798 static void i945_prepare_resume(int s3resume)
799 {
800  int cbmem_was_initted;
801 
802  cbmem_was_initted = !cbmem_recovery(s3resume);
803 
804  romstage_handoff_init(cbmem_was_initted && s3resume);
805 }
806 
807 void i945_late_initialization(int s3resume)
808 {
810 
812 
814 
816 
818 
819  if (CONFIG(NORTHBRIDGE_INTEL_SUBTYPE_I945GM))
821 
823 
824  if (CONFIG(DEBUG_RAM_SETUP))
826 
827  mchbar_write16(SSKPD, 0xcafe);
828 
829  i945_prepare_resume(s3resume);
830 }
#define ARRAY_SIZE(a)
Definition: helpers.h:12
int cbmem_recovery(int s3resume)
Definition: imd_cbmem.c:125
void system_reset(void)
Definition: cf9_reset.c:37
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
static __always_inline uint8_t mchbar_read8(const uintptr_t offset)
Definition: fixed_bars.h:11
#define mchbar_setbits32(addr, set)
Definition: fixed_bars.h:58
static __always_inline void mchbar_write16(const uintptr_t offset, const uint16_t value)
Definition: fixed_bars.h:31
static __always_inline uint32_t epbar_read32(const uintptr_t offset)
Definition: fixed_bars.h:131
#define dmibar_clrbits32(addr, clear)
Definition: fixed_bars.h:117
static __always_inline void mchbar_write32(const uintptr_t offset, const uint32_t value)
Definition: fixed_bars.h:36
static __always_inline uint32_t dmibar_read32(const uintptr_t offset)
Definition: fixed_bars.h:76
static __always_inline void dmibar_write32(const uintptr_t offset, const uint32_t value)
Definition: fixed_bars.h:91
static __always_inline uint16_t dmibar_read16(const uintptr_t offset)
Definition: fixed_bars.h:71
#define mchbar_clrbits16(addr, clear)
Definition: fixed_bars.h:61
#define dmibar_setbits32(addr, set)
Definition: fixed_bars.h:113
static __always_inline uint32_t mchbar_read32(const uintptr_t offset)
Definition: fixed_bars.h:21
static __always_inline uint16_t epbar_read16(const uintptr_t offset)
Definition: fixed_bars.h:126
static __always_inline uint8_t dmibar_read8(const uintptr_t offset)
Definition: fixed_bars.h:66
#define mchbar_setbits16(addr, set)
Definition: fixed_bars.h:57
static __always_inline void epbar_write32(const uintptr_t offset, const uint32_t value)
Definition: fixed_bars.h:146
#define epbar_setbits32(addr, set)
Definition: fixed_bars.h:168
#define SLOTCAP
Definition: gm45.h:198
#define EPVC0RCTL
Definition: gm45.h:375
#define EPLE1A
Definition: gm45.h:390
#define EPPVCCAP1
Definition: gm45.h:371
#define DMIPVCCAP1
Definition: gm45.h:344
#define PEG_CAP
Definition: gm45.h:197
#define DMIVC1RSTS
Definition: gm45.h:353
#define DMILE1D
Definition: gm45.h:358
#define EPVC1RCTL
Definition: gm45.h:379
#define DMILCTL
Definition: gm45.h:364
#define DMILE2D
Definition: gm45.h:360
#define DMIVC1RCTL
Definition: gm45.h:352
#define EPESD
Definition: gm45.h:387
#define EPVC1IST
Definition: gm45.h:385
#define DMILCAP
Definition: gm45.h:363
#define DMILE2A
Definition: gm45.h:361
#define EPVC1RCAP
Definition: gm45.h:378
#define EPVC1MTS
Definition: gm45.h:382
#define DMILE1A
Definition: gm45.h:359
#define EPLE2D
Definition: gm45.h:391
#define EPLE1D
Definition: gm45.h:389
#define EPVC1RSTS
Definition: gm45.h:380
#define DMICC
Definition: dmibar.h:49
#define PAM0
Definition: host_bridge.h:38
#define PAM6
Definition: host_bridge.h:44
#define GGC
Definition: host_bridge.h:9
#define PAM5
Definition: host_bridge.h:43
#define MCHBAR
Definition: host_bridge.h:7
#define PAM2
Definition: host_bridge.h:40
#define PAM1
Definition: host_bridge.h:39
#define DMIBAR
Definition: host_bridge.h:33
#define EPBAR
Definition: host_bridge.h:6
#define DEVEN
Definition: host_bridge.h:16
#define PAM3
Definition: host_bridge.h:41
#define PAM4
Definition: host_bridge.h:42
#define SSKPD
Definition: mchbar.h:36
#define RP2D
Definition: i82801gx.h:175
#define HDD
Definition: i82801gx.h:181
#define RP6D
Definition: i82801gx.h:185
#define RP3D
Definition: i82801gx.h:177
#define V1CAP
Definition: i82801gx.h:164
#define ULD
Definition: i82801gx.h:170
#define RP4D
Definition: i82801gx.h:179
#define RP1D
Definition: i82801gx.h:173
#define ESD
Definition: i82801gx.h:169
#define ULBA
Definition: i82801gx.h:171
#define RP5D
Definition: i82801gx.h:183
#define PVCCAP1
Definition: i945.h:71
#define CLKCFG
Definition: i945.h:217
#define CESTS
Definition: i945.h:76
#define SSTS1
Definition: i945.h:65
void sdram_dump_mchbar_registers(void)
Definition: raminit.c:80
#define DMICTL2
Definition: i945.h:326
#define X60BAR
Definition: i945.h:31
#define PEG_LC
Definition: i945.h:70
#define PEGCC
Definition: i945.h:78
#define PCISTS1
Definition: i945.h:64
#define SLOTSTS
Definition: i945.h:69
#define PEGSTS
Definition: i945.h:79
#define DFT_STRAP1
Definition: i945.h:251
#define PEGTC
Definition: i945.h:77
#define VC0RCTL
Definition: i945.h:72
#define DMIVC0RCTL0
Definition: i945.h:309
#define LE1A
Definition: i945.h:74
#define DMIDRCCFG
Definition: i945.h:330
#define FSBSNPCTL
Definition: i945.h:98
#define UESTS
Definition: i945.h:75
#define DEVEN_D2F0
Definition: i945.h:38
#define MMARB1
Definition: i945.h:155
#define DEVEN_D2F1
Definition: i945.h:39
#define DEVEN_D1F0
Definition: i945.h:37
#define PORTARB
Definition: i945.h:296
#define LE1D
Definition: i945.h:73
#define DMICTL1
Definition: i945.h:325
#define UPMC1
Definition: i945.h:218
#define DSTS
Definition: i945.h:67
#define DEFAULT_X60BAR
Definition: i945.h:6
static __always_inline void pci_or_config32(const struct device *dev, u16 reg, u32 ormask)
Definition: pci_ops.h:191
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline void pci_and_config16(const struct device *dev, u16 reg, u16 andmask)
Definition: pci_ops.h:147
static __always_inline void pci_update_config32(const struct device *dev, u16 reg, u32 mask, u32 or)
Definition: pci_ops.h:120
static __always_inline void pci_update_config8(const struct device *dev, u16 reg, u8 mask, u8 or)
Definition: pci_ops.h:88
static __always_inline void pci_or_config16(const struct device *dev, u16 reg, u16 ormask)
Definition: pci_ops.h:180
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
static __always_inline void pci_write_config16(const struct device *dev, u16 reg, u16 val)
Definition: pci_ops.h:70
static __always_inline void pci_and_config32(const struct device *dev, u16 reg, u32 andmask)
Definition: pci_ops.h:158
static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val)
Definition: pci_ops.h:64
#define LCAP
Definition: pcie.h:16
#define LCTL
Definition: pcie.h:19
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define ESMRAMC
Definition: memmap.c:45
static void ich7_setup_root_complex_topology(void)
Definition: early_init.c:745
static void i945_setup_egress_port(void)
Definition: early_init.c:182
void i945_early_initialization(void)
Definition: early_init.c:775
static void i945_setup_dmi_rcrb(void)
Definition: early_init.c:325
static void ich7_setup_pci_express(void)
Definition: early_init.c:764
static void i945_setup_pci_express_x16(void)
Definition: early_init.c:490
static void i945_prepare_resume(int s3resume)
Definition: early_init.c:798
static void i945_detect_chipset(void)
Definition: early_init.c:85
static void i945m_detect_chipset(void)
Definition: early_init.c:20
void i945_late_initialization(int s3resume)
Definition: early_init.c:807
static void i945_setup_root_complex_topology(void)
Definition: early_init.c:702
static void ich7_setup_dmi_rcrb(void)
Definition: early_init.c:297
static void i945_setup_bars(void)
Definition: early_init.c:136
int i945_silicon_revision(void)
Definition: early_init.c:15
unsigned int get_uint_option(const char *name, const unsigned int fallback)
Definition: option.c:116
#define PCI_CLASS_REVISION
Definition: pci_def.h:40
#define PCI_VENDOR_ID
Definition: pci_def.h:8
void pci_s_deassert_secondary_reset(pci_devfn_t p2p_bridge)
Definition: pci_early.c:17
void pci_s_assert_secondary_reset(pci_devfn_t p2p_bridge)
Definition: pci_early.c:9
void pci_s_bridge_set_secondary(pci_devfn_t p2p_bridge, u8 secondary)
Definition: pci_early.c:25
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
u32 pci_devfn_t
Definition: pci_type.h:8
int romstage_handoff_init(int is_s3_resume)
#define GCS
Definition: lpc.h:36
#define CG
Definition: rcba.h:129
@ HOST_BRIDGE
Definition: reg_access.h:23
#define V0CTL
Definition: pch.h:241
#define V1CTL
Definition: pch.h:243
#define RCBA16(x)
Definition: rcba.h:13
#define RCBA32(x)
Definition: rcba.h:14
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45