northbridge.c 6.1 KB

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