1 // SPDX-License-Identifier: GPL-2.0
3 * From Coreboot northbridge/intel/sandybridge/northbridge.c
5 * Copyright (C) 2007-2009 coresystems GmbH
6 * Copyright (C) 2011 The Chromium Authors
14 #include <asm/intel_regs.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>
22 DECLARE_GLOBAL_DATA_PTR;
24 int bridge_silicon_revision(struct udevice *dev)
26 struct cpuid_result result;
31 stepping = result.eax & 0xf;
32 dm_pci_read_config16(dev, PCI_DEVICE_ID, &bridge_id);
34 return bridge_id | stepping;
37 static int get_pcie_bar(struct udevice *dev, u32 *base, u32 *len)
44 dm_pci_read_config32(dev, PCIEXBAR, &pciexbar_reg);
46 if (!(pciexbar_reg & (1 << 0)))
49 switch ((pciexbar_reg >> 1) & 3) {
51 *base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
53 *len = 256 * 1024 * 1024;
56 *base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
57 (1 << 28) | (1 << 27));
58 *len = 128 * 1024 * 1024;
61 *base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
62 (1 << 28) | (1 << 27) | (1 << 26));
63 *len = 64 * 1024 * 1024;
70 static void add_fixed_resources(struct udevice *dev, int index)
72 u32 pcie_config_base, pcie_config_size;
74 if (get_pcie_bar(dev, &pcie_config_base, &pcie_config_size)) {
75 debug("Adding PCIe config bar base=0x%08x size=0x%x\n",
76 pcie_config_base, pcie_config_size);
80 static void northbridge_dmi_init(struct udevice *dev, int rev)
82 /* Clear error status bits */
83 writel(0xffffffff, DMIBAR_REG(0x1c4));
84 writel(0xffffffff, DMIBAR_REG(0x1d0));
86 /* Steps prior to DMI ASPM */
87 if ((rev & BASE_REV_MASK) == BASE_REV_SNB) {
88 clrsetbits_le32(DMIBAR_REG(0x250), (1 << 22) | (1 << 20),
92 setbits_le32(DMIBAR_REG(0x238), 1 << 29);
94 if (rev >= SNB_STEP_D0) {
95 setbits_le32(DMIBAR_REG(0x1f8), 1 << 16);
96 } else if (rev >= SNB_STEP_D1) {
97 clrsetbits_le32(DMIBAR_REG(0x1f8), 1 << 26, 1 << 16);
98 setbits_le32(DMIBAR_REG(0x1fc), (1 << 12) | (1 << 23));
101 /* Enable ASPM on SNB link, should happen before PCH link */
102 if ((rev & BASE_REV_MASK) == BASE_REV_SNB)
103 setbits_le32(DMIBAR_REG(0xd04), 1 << 4);
105 setbits_le32(DMIBAR_REG(0x88), (1 << 1) | (1 << 0));
108 static void northbridge_init(struct udevice *dev, int rev)
112 add_fixed_resources(dev, 6);
113 northbridge_dmi_init(dev, rev);
115 bridge_type = readl(MCHBAR_REG(0x5f10));
116 bridge_type &= ~0xff;
118 if ((rev & BASE_REV_MASK) == BASE_REV_IVB) {
119 /* Enable Power Aware Interrupt Routing - fixed priority */
120 clrsetbits_8(MCHBAR_REG(0x5418), 0xf, 0x4);
122 /* 30h for IvyBridge */
125 /* 20h for Sandybridge */
128 writel(bridge_type, MCHBAR_REG(0x5f10));
131 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
132 * that BIOS has initialized memory and power management
134 setbits_8(MCHBAR_REG(BIOS_RESET_CPL), 1);
135 debug("Set BIOS_RESET_CPL\n");
137 /* Configure turbo power limits 1ms after reset complete bit */
139 set_power_limits(28);
142 * CPUs with configurable TDP also need power limits set
143 * in MCHBAR. Use same values from MSR_PKG_POWER_LIMIT.
145 if (cpu_ivybridge_config_tdp_levels()) {
146 msr_t msr = msr_read(MSR_PKG_POWER_LIMIT);
148 writel(msr.lo, MCHBAR_REG(0x59A0));
149 writel(msr.hi, MCHBAR_REG(0x59A4));
152 /* Set here before graphics PM init */
153 writel(0x00100001, MCHBAR_REG(0x5500));
156 static void sandybridge_setup_northbridge_bars(struct udevice *dev)
158 /* Set up all hardcoded northbridge BARs */
159 debug("Setting up static registers\n");
160 dm_pci_write_config32(dev, EPBAR, DEFAULT_EPBAR | 1);
161 dm_pci_write_config32(dev, EPBAR + 4, (0LL + DEFAULT_EPBAR) >> 32);
162 dm_pci_write_config32(dev, MCHBAR, MCH_BASE_ADDRESS | 1);
163 dm_pci_write_config32(dev, MCHBAR + 4, (0LL + MCH_BASE_ADDRESS) >> 32);
164 /* 64MB - busses 0-63 */
165 dm_pci_write_config32(dev, PCIEXBAR, DEFAULT_PCIEXBAR | 5);
166 dm_pci_write_config32(dev, PCIEXBAR + 4,
167 (0LL + DEFAULT_PCIEXBAR) >> 32);
168 dm_pci_write_config32(dev, DMIBAR, DEFAULT_DMIBAR | 1);
169 dm_pci_write_config32(dev, DMIBAR + 4, (0LL + DEFAULT_DMIBAR) >> 32);
171 /* Set C0000-FFFFF to access RAM on both reads and writes */
172 dm_pci_write_config8(dev, PAM0, 0x30);
173 dm_pci_write_config8(dev, PAM1, 0x33);
174 dm_pci_write_config8(dev, PAM2, 0x33);
175 dm_pci_write_config8(dev, PAM3, 0x33);
176 dm_pci_write_config8(dev, PAM4, 0x33);
177 dm_pci_write_config8(dev, PAM5, 0x33);
178 dm_pci_write_config8(dev, PAM6, 0x33);
182 * sandybridge_init_iommu() - Set up IOMMU so that azalia can be used
184 * It is not obvious where these values come from. They may be undocumented.
186 static void sandybridge_init_iommu(struct udevice *dev)
190 dm_pci_read_config32(dev, 0xe4, &capid0_a);
191 if (capid0_a & (1 << 23)) {
192 log_debug("capid0_a not needed\n");
197 writel(IOMMU_BASE1 >> 32, MCHBAR_REG(0x5404));
198 writel(IOMMU_BASE1 | 1, MCHBAR_REG(0x5400));
199 writel(IOMMU_BASE2 >> 32, MCHBAR_REG(0x5414));
200 writel(IOMMU_BASE2 | 1, MCHBAR_REG(0x5410));
203 writel(0x80000000, IOMMU_BASE1 + 0xff0);
205 /* Enable azalia sound */
206 writel(0x20000000, IOMMU_BASE2 + 0xff0);
207 writel(0xa0000000, IOMMU_BASE2 + 0xff0);
210 static int bd82x6x_northbridge_early_init(struct udevice *dev)
212 const int chipset_type = SANDYBRIDGE_MOBILE;
216 /* Device ID Override Enable should be done very early */
217 dm_pci_read_config32(dev, 0xe4, &capid0_a);
218 if (capid0_a & (1 << 10)) {
219 dm_pci_read_config8(dev, 0xf3, ®8);
220 reg8 &= ~7; /* Clear 2:0 */
222 if (chipset_type == SANDYBRIDGE_MOBILE)
223 reg8 |= 1; /* Set bit 0 */
225 dm_pci_write_config8(dev, 0xf3, reg8);
228 sandybridge_setup_northbridge_bars(dev);
230 /* Setup IOMMU BARs */
231 sandybridge_init_iommu(dev);
234 dm_pci_write_config32(dev, DEVEN, DEVEN_HOST | DEVEN_IGD);
239 static int bd82x6x_northbridge_probe(struct udevice *dev)
243 if (!(gd->flags & GD_FLG_RELOC))
244 return bd82x6x_northbridge_early_init(dev);
246 rev = bridge_silicon_revision(dev);
247 northbridge_init(dev, rev);
252 static const struct udevice_id bd82x6x_northbridge_ids[] = {
253 { .compatible = "intel,bd82x6x-northbridge" },
257 U_BOOT_DRIVER(bd82x6x_northbridge_drv) = {
258 .name = "bd82x6x_northbridge",
259 .id = UCLASS_NORTHBRIDGE,
260 .of_match = bd82x6x_northbridge_ids,
261 .probe = bd82x6x_northbridge_probe,