northbridge.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * From Coreboot northbridge/intel/sandybridge/northbridge.c
  4. *
  5. * Copyright (C) 2007-2009 coresystems GmbH
  6. * Copyright (C) 2011 The Chromium Authors
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <asm/msr.h>
  11. #include <asm/cpu.h>
  12. #include <asm/intel_regs.h>
  13. #include <asm/io.h>
  14. #include <asm/pci.h>
  15. #include <asm/processor.h>
  16. #include <asm/arch/pch.h>
  17. #include <asm/arch/model_206ax.h>
  18. #include <asm/arch/sandybridge.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. int bridge_silicon_revision(struct udevice *dev)
  21. {
  22. struct cpuid_result result;
  23. u16 bridge_id;
  24. u8 stepping;
  25. result = cpuid(1);
  26. stepping = result.eax & 0xf;
  27. dm_pci_read_config16(dev, PCI_DEVICE_ID, &bridge_id);
  28. bridge_id &= 0xf0;
  29. return bridge_id | stepping;
  30. }
  31. static int get_pcie_bar(struct udevice *dev, u32 *base, u32 *len)
  32. {
  33. u32 pciexbar_reg;
  34. *base = 0;
  35. *len = 0;
  36. dm_pci_read_config32(dev, PCIEXBAR, &pciexbar_reg);
  37. if (!(pciexbar_reg & (1 << 0)))
  38. return 0;
  39. switch ((pciexbar_reg >> 1) & 3) {
  40. case 0: /* 256MB */
  41. *base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
  42. (1 << 28));
  43. *len = 256 * 1024 * 1024;
  44. return 1;
  45. case 1: /* 128M */
  46. *base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
  47. (1 << 28) | (1 << 27));
  48. *len = 128 * 1024 * 1024;
  49. return 1;
  50. case 2: /* 64M */
  51. *base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
  52. (1 << 28) | (1 << 27) | (1 << 26));
  53. *len = 64 * 1024 * 1024;
  54. return 1;
  55. }
  56. return 0;
  57. }
  58. static void add_fixed_resources(struct udevice *dev, int index)
  59. {
  60. u32 pcie_config_base, pcie_config_size;
  61. if (get_pcie_bar(dev, &pcie_config_base, &pcie_config_size)) {
  62. debug("Adding PCIe config bar base=0x%08x size=0x%x\n",
  63. pcie_config_base, pcie_config_size);
  64. }
  65. }
  66. static void northbridge_dmi_init(struct udevice *dev, int rev)
  67. {
  68. /* Clear error status bits */
  69. writel(0xffffffff, DMIBAR_REG(0x1c4));
  70. writel(0xffffffff, DMIBAR_REG(0x1d0));
  71. /* Steps prior to DMI ASPM */
  72. if ((rev & BASE_REV_MASK) == BASE_REV_SNB) {
  73. clrsetbits_le32(DMIBAR_REG(0x250), (1 << 22) | (1 << 20),
  74. 1 << 21);
  75. }
  76. setbits_le32(DMIBAR_REG(0x238), 1 << 29);
  77. if (rev >= SNB_STEP_D0) {
  78. setbits_le32(DMIBAR_REG(0x1f8), 1 << 16);
  79. } else if (rev >= SNB_STEP_D1) {
  80. clrsetbits_le32(DMIBAR_REG(0x1f8), 1 << 26, 1 << 16);
  81. setbits_le32(DMIBAR_REG(0x1fc), (1 << 12) | (1 << 23));
  82. }
  83. /* Enable ASPM on SNB link, should happen before PCH link */
  84. if ((rev & BASE_REV_MASK) == BASE_REV_SNB)
  85. setbits_le32(DMIBAR_REG(0xd04), 1 << 4);
  86. setbits_le32(DMIBAR_REG(0x88), (1 << 1) | (1 << 0));
  87. }
  88. static void northbridge_init(struct udevice *dev, int rev)
  89. {
  90. u32 bridge_type;
  91. add_fixed_resources(dev, 6);
  92. northbridge_dmi_init(dev, rev);
  93. bridge_type = readl(MCHBAR_REG(0x5f10));
  94. bridge_type &= ~0xff;
  95. if ((rev & BASE_REV_MASK) == BASE_REV_IVB) {
  96. /* Enable Power Aware Interrupt Routing - fixed priority */
  97. clrsetbits_8(MCHBAR_REG(0x5418), 0xf, 0x4);
  98. /* 30h for IvyBridge */
  99. bridge_type |= 0x30;
  100. } else {
  101. /* 20h for Sandybridge */
  102. bridge_type |= 0x20;
  103. }
  104. writel(bridge_type, MCHBAR_REG(0x5f10));
  105. /*
  106. * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
  107. * that BIOS has initialized memory and power management
  108. */
  109. setbits_8(MCHBAR_REG(BIOS_RESET_CPL), 1);
  110. debug("Set BIOS_RESET_CPL\n");
  111. /* Configure turbo power limits 1ms after reset complete bit */
  112. mdelay(1);
  113. set_power_limits(28);
  114. /*
  115. * CPUs with configurable TDP also need power limits set
  116. * in MCHBAR. Use same values from MSR_PKG_POWER_LIMIT.
  117. */
  118. if (cpu_config_tdp_levels()) {
  119. msr_t msr = msr_read(MSR_PKG_POWER_LIMIT);
  120. writel(msr.lo, MCHBAR_REG(0x59A0));
  121. writel(msr.hi, MCHBAR_REG(0x59A4));
  122. }
  123. /* Set here before graphics PM init */
  124. writel(0x00100001, MCHBAR_REG(0x5500));
  125. }
  126. static void sandybridge_setup_northbridge_bars(struct udevice *dev)
  127. {
  128. /* Set up all hardcoded northbridge BARs */
  129. debug("Setting up static registers\n");
  130. dm_pci_write_config32(dev, EPBAR, DEFAULT_EPBAR | 1);
  131. dm_pci_write_config32(dev, EPBAR + 4, (0LL + DEFAULT_EPBAR) >> 32);
  132. dm_pci_write_config32(dev, MCHBAR, MCH_BASE_ADDRESS | 1);
  133. dm_pci_write_config32(dev, MCHBAR + 4, (0LL + MCH_BASE_ADDRESS) >> 32);
  134. /* 64MB - busses 0-63 */
  135. dm_pci_write_config32(dev, PCIEXBAR, DEFAULT_PCIEXBAR | 5);
  136. dm_pci_write_config32(dev, PCIEXBAR + 4,
  137. (0LL + DEFAULT_PCIEXBAR) >> 32);
  138. dm_pci_write_config32(dev, DMIBAR, DEFAULT_DMIBAR | 1);
  139. dm_pci_write_config32(dev, DMIBAR + 4, (0LL + DEFAULT_DMIBAR) >> 32);
  140. /* Set C0000-FFFFF to access RAM on both reads and writes */
  141. dm_pci_write_config8(dev, PAM0, 0x30);
  142. dm_pci_write_config8(dev, PAM1, 0x33);
  143. dm_pci_write_config8(dev, PAM2, 0x33);
  144. dm_pci_write_config8(dev, PAM3, 0x33);
  145. dm_pci_write_config8(dev, PAM4, 0x33);
  146. dm_pci_write_config8(dev, PAM5, 0x33);
  147. dm_pci_write_config8(dev, PAM6, 0x33);
  148. }
  149. static int bd82x6x_northbridge_early_init(struct udevice *dev)
  150. {
  151. const int chipset_type = SANDYBRIDGE_MOBILE;
  152. u32 capid0_a;
  153. u8 reg8;
  154. /* Device ID Override Enable should be done very early */
  155. dm_pci_read_config32(dev, 0xe4, &capid0_a);
  156. if (capid0_a & (1 << 10)) {
  157. dm_pci_read_config8(dev, 0xf3, &reg8);
  158. reg8 &= ~7; /* Clear 2:0 */
  159. if (chipset_type == SANDYBRIDGE_MOBILE)
  160. reg8 |= 1; /* Set bit 0 */
  161. dm_pci_write_config8(dev, 0xf3, reg8);
  162. }
  163. sandybridge_setup_northbridge_bars(dev);
  164. /* Device Enable */
  165. dm_pci_write_config32(dev, DEVEN, DEVEN_HOST | DEVEN_IGD);
  166. return 0;
  167. }
  168. static int bd82x6x_northbridge_probe(struct udevice *dev)
  169. {
  170. int rev;
  171. if (!(gd->flags & GD_FLG_RELOC))
  172. return bd82x6x_northbridge_early_init(dev);
  173. rev = bridge_silicon_revision(dev);
  174. northbridge_init(dev, rev);
  175. return 0;
  176. }
  177. static const struct udevice_id bd82x6x_northbridge_ids[] = {
  178. { .compatible = "intel,bd82x6x-northbridge" },
  179. { }
  180. };
  181. U_BOOT_DRIVER(bd82x6x_northbridge_drv) = {
  182. .name = "bd82x6x_northbridge",
  183. .id = UCLASS_NORTHBRIDGE,
  184. .of_match = bd82x6x_northbridge_ids,
  185. .probe = bd82x6x_northbridge_probe,
  186. };