Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * From Coreboot northbridge/intel/sandybridge/northbridge.c |
| 4 | * |
| 5 | * Copyright (C) 2007-2009 coresystems GmbH |
| 6 | * Copyright (C) 2011 The Chromium Authors |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 6b7f76d | 2016-01-17 16:11:27 -0700 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 12 | #include <asm/msr.h> |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 13 | #include <asm/cpu.h> |
Simon Glass | 5535730 | 2016-03-11 22:06:55 -0700 | [diff] [blame] | 14 | #include <asm/intel_regs.h> |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 15 | #include <asm/io.h> |
| 16 | #include <asm/pci.h> |
| 17 | #include <asm/processor.h> |
| 18 | #include <asm/arch/pch.h> |
| 19 | #include <asm/arch/model_206ax.h> |
| 20 | #include <asm/arch/sandybridge.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 21 | #include <linux/delay.h> |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 22 | |
Simon Glass | d87b092 | 2017-01-16 07:03:37 -0700 | [diff] [blame] | 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 25 | int bridge_silicon_revision(struct udevice *dev) |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 26 | { |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 27 | struct cpuid_result result; |
| 28 | u16 bridge_id; |
| 29 | u8 stepping; |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 30 | |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 31 | result = cpuid(1); |
| 32 | stepping = result.eax & 0xf; |
| 33 | dm_pci_read_config16(dev, PCI_DEVICE_ID, &bridge_id); |
| 34 | bridge_id &= 0xf0; |
| 35 | return bridge_id | stepping; |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Simon Glass | e5bdccd | 2016-01-17 16:11:32 -0700 | [diff] [blame] | 38 | static int get_pcie_bar(struct udevice *dev, u32 *base, u32 *len) |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 39 | { |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 40 | u32 pciexbar_reg; |
| 41 | |
| 42 | *base = 0; |
| 43 | *len = 0; |
| 44 | |
Simon Glass | e5bdccd | 2016-01-17 16:11:32 -0700 | [diff] [blame] | 45 | dm_pci_read_config32(dev, PCIEXBAR, &pciexbar_reg); |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 46 | |
| 47 | if (!(pciexbar_reg & (1 << 0))) |
| 48 | return 0; |
| 49 | |
| 50 | switch ((pciexbar_reg >> 1) & 3) { |
| 51 | case 0: /* 256MB */ |
| 52 | *base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) | |
| 53 | (1 << 28)); |
| 54 | *len = 256 * 1024 * 1024; |
| 55 | return 1; |
| 56 | case 1: /* 128M */ |
| 57 | *base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) | |
| 58 | (1 << 28) | (1 << 27)); |
| 59 | *len = 128 * 1024 * 1024; |
| 60 | return 1; |
| 61 | case 2: /* 64M */ |
| 62 | *base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) | |
| 63 | (1 << 28) | (1 << 27) | (1 << 26)); |
| 64 | *len = 64 * 1024 * 1024; |
| 65 | return 1; |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
Simon Glass | e5bdccd | 2016-01-17 16:11:32 -0700 | [diff] [blame] | 71 | static void add_fixed_resources(struct udevice *dev, int index) |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 72 | { |
| 73 | u32 pcie_config_base, pcie_config_size; |
| 74 | |
Simon Glass | e5bdccd | 2016-01-17 16:11:32 -0700 | [diff] [blame] | 75 | if (get_pcie_bar(dev, &pcie_config_base, &pcie_config_size)) { |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 76 | debug("Adding PCIe config bar base=0x%08x size=0x%x\n", |
| 77 | pcie_config_base, pcie_config_size); |
| 78 | } |
| 79 | } |
| 80 | |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 81 | static void northbridge_dmi_init(struct udevice *dev, int rev) |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 82 | { |
| 83 | /* Clear error status bits */ |
| 84 | writel(0xffffffff, DMIBAR_REG(0x1c4)); |
| 85 | writel(0xffffffff, DMIBAR_REG(0x1d0)); |
| 86 | |
| 87 | /* Steps prior to DMI ASPM */ |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 88 | if ((rev & BASE_REV_MASK) == BASE_REV_SNB) { |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 89 | clrsetbits_le32(DMIBAR_REG(0x250), (1 << 22) | (1 << 20), |
| 90 | 1 << 21); |
| 91 | } |
| 92 | |
| 93 | setbits_le32(DMIBAR_REG(0x238), 1 << 29); |
| 94 | |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 95 | if (rev >= SNB_STEP_D0) { |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 96 | setbits_le32(DMIBAR_REG(0x1f8), 1 << 16); |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 97 | } else if (rev >= SNB_STEP_D1) { |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 98 | clrsetbits_le32(DMIBAR_REG(0x1f8), 1 << 26, 1 << 16); |
| 99 | setbits_le32(DMIBAR_REG(0x1fc), (1 << 12) | (1 << 23)); |
| 100 | } |
| 101 | |
| 102 | /* Enable ASPM on SNB link, should happen before PCH link */ |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 103 | if ((rev & BASE_REV_MASK) == BASE_REV_SNB) |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 104 | setbits_le32(DMIBAR_REG(0xd04), 1 << 4); |
| 105 | |
| 106 | setbits_le32(DMIBAR_REG(0x88), (1 << 1) | (1 << 0)); |
| 107 | } |
| 108 | |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 109 | static void northbridge_init(struct udevice *dev, int rev) |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 110 | { |
| 111 | u32 bridge_type; |
| 112 | |
| 113 | add_fixed_resources(dev, 6); |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 114 | northbridge_dmi_init(dev, rev); |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 115 | |
| 116 | bridge_type = readl(MCHBAR_REG(0x5f10)); |
| 117 | bridge_type &= ~0xff; |
| 118 | |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 119 | if ((rev & BASE_REV_MASK) == BASE_REV_IVB) { |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 120 | /* Enable Power Aware Interrupt Routing - fixed priority */ |
| 121 | clrsetbits_8(MCHBAR_REG(0x5418), 0xf, 0x4); |
| 122 | |
| 123 | /* 30h for IvyBridge */ |
| 124 | bridge_type |= 0x30; |
| 125 | } else { |
| 126 | /* 20h for Sandybridge */ |
| 127 | bridge_type |= 0x20; |
| 128 | } |
| 129 | writel(bridge_type, MCHBAR_REG(0x5f10)); |
| 130 | |
| 131 | /* |
| 132 | * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU |
| 133 | * that BIOS has initialized memory and power management |
| 134 | */ |
| 135 | setbits_8(MCHBAR_REG(BIOS_RESET_CPL), 1); |
| 136 | debug("Set BIOS_RESET_CPL\n"); |
| 137 | |
| 138 | /* Configure turbo power limits 1ms after reset complete bit */ |
| 139 | mdelay(1); |
| 140 | set_power_limits(28); |
| 141 | |
| 142 | /* |
| 143 | * CPUs with configurable TDP also need power limits set |
| 144 | * in MCHBAR. Use same values from MSR_PKG_POWER_LIMIT. |
| 145 | */ |
Simon Glass | b12689d | 2019-09-25 08:56:38 -0600 | [diff] [blame] | 146 | if (cpu_ivybridge_config_tdp_levels()) { |
Simon Glass | 61612ed | 2014-11-24 21:18:18 -0700 | [diff] [blame] | 147 | msr_t msr = msr_read(MSR_PKG_POWER_LIMIT); |
| 148 | |
| 149 | writel(msr.lo, MCHBAR_REG(0x59A0)); |
| 150 | writel(msr.hi, MCHBAR_REG(0x59A4)); |
| 151 | } |
| 152 | |
| 153 | /* Set here before graphics PM init */ |
| 154 | writel(0x00100001, MCHBAR_REG(0x5500)); |
| 155 | } |
| 156 | |
Simon Glass | 6b7f76d | 2016-01-17 16:11:27 -0700 | [diff] [blame] | 157 | static void sandybridge_setup_northbridge_bars(struct udevice *dev) |
| 158 | { |
| 159 | /* Set up all hardcoded northbridge BARs */ |
| 160 | debug("Setting up static registers\n"); |
| 161 | dm_pci_write_config32(dev, EPBAR, DEFAULT_EPBAR | 1); |
| 162 | dm_pci_write_config32(dev, EPBAR + 4, (0LL + DEFAULT_EPBAR) >> 32); |
Simon Glass | 5535730 | 2016-03-11 22:06:55 -0700 | [diff] [blame] | 163 | dm_pci_write_config32(dev, MCHBAR, MCH_BASE_ADDRESS | 1); |
| 164 | dm_pci_write_config32(dev, MCHBAR + 4, (0LL + MCH_BASE_ADDRESS) >> 32); |
Simon Glass | 6b7f76d | 2016-01-17 16:11:27 -0700 | [diff] [blame] | 165 | /* 64MB - busses 0-63 */ |
| 166 | dm_pci_write_config32(dev, PCIEXBAR, DEFAULT_PCIEXBAR | 5); |
| 167 | dm_pci_write_config32(dev, PCIEXBAR + 4, |
| 168 | (0LL + DEFAULT_PCIEXBAR) >> 32); |
| 169 | dm_pci_write_config32(dev, DMIBAR, DEFAULT_DMIBAR | 1); |
| 170 | dm_pci_write_config32(dev, DMIBAR + 4, (0LL + DEFAULT_DMIBAR) >> 32); |
| 171 | |
| 172 | /* Set C0000-FFFFF to access RAM on both reads and writes */ |
| 173 | dm_pci_write_config8(dev, PAM0, 0x30); |
| 174 | dm_pci_write_config8(dev, PAM1, 0x33); |
| 175 | dm_pci_write_config8(dev, PAM2, 0x33); |
| 176 | dm_pci_write_config8(dev, PAM3, 0x33); |
| 177 | dm_pci_write_config8(dev, PAM4, 0x33); |
| 178 | dm_pci_write_config8(dev, PAM5, 0x33); |
| 179 | dm_pci_write_config8(dev, PAM6, 0x33); |
| 180 | } |
| 181 | |
Simon Glass | e7ceeef | 2019-02-16 20:24:57 -0700 | [diff] [blame] | 182 | /** |
| 183 | * sandybridge_init_iommu() - Set up IOMMU so that azalia can be used |
| 184 | * |
| 185 | * It is not obvious where these values come from. They may be undocumented. |
| 186 | */ |
| 187 | static void sandybridge_init_iommu(struct udevice *dev) |
| 188 | { |
| 189 | u32 capid0_a; |
| 190 | |
| 191 | dm_pci_read_config32(dev, 0xe4, &capid0_a); |
| 192 | if (capid0_a & (1 << 23)) { |
| 193 | log_debug("capid0_a not needed\n"); |
| 194 | return; |
| 195 | } |
| 196 | |
| 197 | /* setup BARs */ |
| 198 | writel(IOMMU_BASE1 >> 32, MCHBAR_REG(0x5404)); |
| 199 | writel(IOMMU_BASE1 | 1, MCHBAR_REG(0x5400)); |
| 200 | writel(IOMMU_BASE2 >> 32, MCHBAR_REG(0x5414)); |
| 201 | writel(IOMMU_BASE2 | 1, MCHBAR_REG(0x5410)); |
| 202 | |
| 203 | /* lock policies */ |
| 204 | writel(0x80000000, IOMMU_BASE1 + 0xff0); |
| 205 | |
| 206 | /* Enable azalia sound */ |
| 207 | writel(0x20000000, IOMMU_BASE2 + 0xff0); |
| 208 | writel(0xa0000000, IOMMU_BASE2 + 0xff0); |
| 209 | } |
| 210 | |
Simon Glass | 4fa56b1 | 2016-01-17 16:11:31 -0700 | [diff] [blame] | 211 | static int bd82x6x_northbridge_early_init(struct udevice *dev) |
Simon Glass | 6b7f76d | 2016-01-17 16:11:27 -0700 | [diff] [blame] | 212 | { |
| 213 | const int chipset_type = SANDYBRIDGE_MOBILE; |
| 214 | u32 capid0_a; |
| 215 | u8 reg8; |
| 216 | |
Simon Glass | 6b7f76d | 2016-01-17 16:11:27 -0700 | [diff] [blame] | 217 | /* Device ID Override Enable should be done very early */ |
| 218 | dm_pci_read_config32(dev, 0xe4, &capid0_a); |
| 219 | if (capid0_a & (1 << 10)) { |
| 220 | dm_pci_read_config8(dev, 0xf3, ®8); |
| 221 | reg8 &= ~7; /* Clear 2:0 */ |
| 222 | |
| 223 | if (chipset_type == SANDYBRIDGE_MOBILE) |
| 224 | reg8 |= 1; /* Set bit 0 */ |
| 225 | |
| 226 | dm_pci_write_config8(dev, 0xf3, reg8); |
| 227 | } |
| 228 | |
| 229 | sandybridge_setup_northbridge_bars(dev); |
| 230 | |
Simon Glass | e7ceeef | 2019-02-16 20:24:57 -0700 | [diff] [blame] | 231 | /* Setup IOMMU BARs */ |
| 232 | sandybridge_init_iommu(dev); |
| 233 | |
Simon Glass | 6b7f76d | 2016-01-17 16:11:27 -0700 | [diff] [blame] | 234 | /* Device Enable */ |
| 235 | dm_pci_write_config32(dev, DEVEN, DEVEN_HOST | DEVEN_IGD); |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
Simon Glass | 4fa56b1 | 2016-01-17 16:11:31 -0700 | [diff] [blame] | 240 | static int bd82x6x_northbridge_probe(struct udevice *dev) |
| 241 | { |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 242 | int rev; |
| 243 | |
Simon Glass | 4fa56b1 | 2016-01-17 16:11:31 -0700 | [diff] [blame] | 244 | if (!(gd->flags & GD_FLG_RELOC)) |
| 245 | return bd82x6x_northbridge_early_init(dev); |
| 246 | |
Simon Glass | 11f76a7 | 2016-01-17 16:11:54 -0700 | [diff] [blame] | 247 | rev = bridge_silicon_revision(dev); |
| 248 | northbridge_init(dev, rev); |
Simon Glass | 4fa56b1 | 2016-01-17 16:11:31 -0700 | [diff] [blame] | 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Simon Glass | 6b7f76d | 2016-01-17 16:11:27 -0700 | [diff] [blame] | 253 | static const struct udevice_id bd82x6x_northbridge_ids[] = { |
| 254 | { .compatible = "intel,bd82x6x-northbridge" }, |
| 255 | { } |
| 256 | }; |
| 257 | |
| 258 | U_BOOT_DRIVER(bd82x6x_northbridge_drv) = { |
| 259 | .name = "bd82x6x_northbridge", |
| 260 | .id = UCLASS_NORTHBRIDGE, |
| 261 | .of_match = bd82x6x_northbridge_ids, |
| 262 | .probe = bd82x6x_northbridge_probe, |
| 263 | }; |