early_init.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * From Coreboot
  3. *
  4. * Copyright (C) 2007-2010 coresystems GmbH
  5. * Copyright (C) 2011 Google Inc
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <asm/io.h>
  11. #include <asm/pci.h>
  12. #include <asm/arch/pch.h>
  13. #include <asm/arch/sandybridge.h>
  14. static void sandybridge_setup_bars(pci_dev_t pch_dev, pci_dev_t lpc_dev)
  15. {
  16. /* Setting up Southbridge. In the northbridge code. */
  17. debug("Setting up static southbridge registers\n");
  18. x86_pci_write_config32(lpc_dev, PCH_RCBA_BASE, DEFAULT_RCBA | 1);
  19. x86_pci_write_config32(lpc_dev, PMBASE, DEFAULT_PMBASE | 1);
  20. x86_pci_write_config8(lpc_dev, ACPI_CNTL, 0x80); /* Enable ACPI BAR */
  21. debug("Disabling watchdog reboot\n");
  22. setbits_le32(RCB_REG(GCS), 1 >> 5); /* No reset */
  23. outw(1 << 11, DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
  24. /* Set up all hardcoded northbridge BARs */
  25. debug("Setting up static registers\n");
  26. x86_pci_write_config32(pch_dev, EPBAR, DEFAULT_EPBAR | 1);
  27. x86_pci_write_config32(pch_dev, EPBAR + 4, (0LL + DEFAULT_EPBAR) >> 32);
  28. x86_pci_write_config32(pch_dev, MCHBAR, DEFAULT_MCHBAR | 1);
  29. x86_pci_write_config32(pch_dev, MCHBAR + 4,
  30. (0LL + DEFAULT_MCHBAR) >> 32);
  31. /* 64MB - busses 0-63 */
  32. x86_pci_write_config32(pch_dev, PCIEXBAR, DEFAULT_PCIEXBAR | 5);
  33. x86_pci_write_config32(pch_dev, PCIEXBAR + 4,
  34. (0LL + DEFAULT_PCIEXBAR) >> 32);
  35. x86_pci_write_config32(pch_dev, DMIBAR, DEFAULT_DMIBAR | 1);
  36. x86_pci_write_config32(pch_dev, DMIBAR + 4,
  37. (0LL + DEFAULT_DMIBAR) >> 32);
  38. /* Set C0000-FFFFF to access RAM on both reads and writes */
  39. x86_pci_write_config8(pch_dev, PAM0, 0x30);
  40. x86_pci_write_config8(pch_dev, PAM1, 0x33);
  41. x86_pci_write_config8(pch_dev, PAM2, 0x33);
  42. x86_pci_write_config8(pch_dev, PAM3, 0x33);
  43. x86_pci_write_config8(pch_dev, PAM4, 0x33);
  44. x86_pci_write_config8(pch_dev, PAM5, 0x33);
  45. x86_pci_write_config8(pch_dev, PAM6, 0x33);
  46. }
  47. static void sandybridge_setup_graphics(pci_dev_t pch_dev, pci_dev_t video_dev)
  48. {
  49. u32 reg32;
  50. u16 reg16;
  51. u8 reg8;
  52. reg16 = x86_pci_read_config16(video_dev, PCI_DEVICE_ID);
  53. switch (reg16) {
  54. case 0x0102: /* GT1 Desktop */
  55. case 0x0106: /* GT1 Mobile */
  56. case 0x010a: /* GT1 Server */
  57. case 0x0112: /* GT2 Desktop */
  58. case 0x0116: /* GT2 Mobile */
  59. case 0x0122: /* GT2 Desktop >=1.3GHz */
  60. case 0x0126: /* GT2 Mobile >=1.3GHz */
  61. case 0x0156: /* IvyBridge */
  62. case 0x0166: /* IvyBridge */
  63. break;
  64. default:
  65. debug("Graphics not supported by this CPU/chipset\n");
  66. return;
  67. }
  68. debug("Initialising Graphics\n");
  69. /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
  70. reg16 = x86_pci_read_config16(pch_dev, GGC);
  71. reg16 &= ~0x00f8;
  72. reg16 |= 1 << 3;
  73. /* Program GTT memory by setting GGC[9:8] = 2MB */
  74. reg16 &= ~0x0300;
  75. reg16 |= 2 << 8;
  76. /* Enable VGA decode */
  77. reg16 &= ~0x0002;
  78. x86_pci_write_config16(pch_dev, GGC, reg16);
  79. /* Enable 256MB aperture */
  80. reg8 = x86_pci_read_config8(video_dev, MSAC);
  81. reg8 &= ~0x06;
  82. reg8 |= 0x02;
  83. x86_pci_write_config8(video_dev, MSAC, reg8);
  84. /* Erratum workarounds */
  85. reg32 = readl(MCHBAR_REG(0x5f00));
  86. reg32 |= (1 << 9) | (1 << 10);
  87. writel(reg32, MCHBAR_REG(0x5f00));
  88. /* Enable SA Clock Gating */
  89. reg32 = readl(MCHBAR_REG(0x5f00));
  90. writel(reg32 | 1, MCHBAR_REG(0x5f00));
  91. /* GPU RC6 workaround for sighting 366252 */
  92. reg32 = readl(MCHBAR_REG(0x5d14));
  93. reg32 |= (1 << 31);
  94. writel(reg32, MCHBAR_REG(0x5d14));
  95. /* VLW */
  96. reg32 = readl(MCHBAR_REG(0x6120));
  97. reg32 &= ~(1 << 0);
  98. writel(reg32, MCHBAR_REG(0x6120));
  99. reg32 = readl(MCHBAR_REG(0x5418));
  100. reg32 |= (1 << 4) | (1 << 5);
  101. writel(reg32, MCHBAR_REG(0x5418));
  102. }
  103. void sandybridge_early_init(int chipset_type)
  104. {
  105. pci_dev_t pch_dev = PCH_DEV;
  106. pci_dev_t video_dev = PCH_VIDEO_DEV;
  107. pci_dev_t lpc_dev = PCH_LPC_DEV;
  108. u32 capid0_a;
  109. u8 reg8;
  110. /* Device ID Override Enable should be done very early */
  111. capid0_a = x86_pci_read_config32(pch_dev, 0xe4);
  112. if (capid0_a & (1 << 10)) {
  113. reg8 = x86_pci_read_config8(pch_dev, 0xf3);
  114. reg8 &= ~7; /* Clear 2:0 */
  115. if (chipset_type == SANDYBRIDGE_MOBILE)
  116. reg8 |= 1; /* Set bit 0 */
  117. x86_pci_write_config8(pch_dev, 0xf3, reg8);
  118. }
  119. /* Setup all BARs required for early PCIe and raminit */
  120. sandybridge_setup_bars(pch_dev, lpc_dev);
  121. /* Device Enable */
  122. x86_pci_write_config32(pch_dev, DEVEN, DEVEN_HOST | DEVEN_IGD);
  123. sandybridge_setup_graphics(pch_dev, video_dev);
  124. }