blob: 74ae4f5e08659f72ea691e0546ac72df3681b648 [file] [log] [blame]
Stefan Reinauer00636b02012-04-04 00:08:51 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2010 coresystems GmbH
Patrick Rudolph2cdb65d2019-03-24 18:08:43 +01005 * Copyright (C) 2015 secunet Security Networks AG
Stefan Reinauer00636b02012-04-04 00:08:51 +02006 * Copyright (C) 2011 Google Inc
Patrick Rudolph2cdb65d2019-03-24 18:08:43 +01007 * Copyright (C) 2018 Patrick Rudolph <patrick.rudolph@9elements.com>
Stefan Reinauer00636b02012-04-04 00:08:51 +02008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Stefan Reinauer00636b02012-04-04 00:08:51 +020017 */
18
Stefan Reinauer00636b02012-04-04 00:08:51 +020019#include <console/console.h>
Patrick Rudolph2cdb65d2019-03-24 18:08:43 +010020#include <device/mmio.h>
21#include <device/device.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020022#include <device/pci_ops.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020023#include <device/pci_def.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +020024#include <option.h>
Kyösti Mälkkie39a8a92016-06-25 11:40:00 +030025#include <romstage_handoff.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020026#include <types.h>
27
Stefan Reinauer00636b02012-04-04 00:08:51 +020028#include "sandybridge.h"
Stefan Reinauer00636b02012-04-04 00:08:51 +020029
Patrick Rudolph2cdb65d2019-03-24 18:08:43 +010030static void systemagent_vtd_init(void)
31{
32 const u32 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), CAPID0_A);
33 if (capid0_a & (1 << 23))
34 return;
35
36 /* setup BARs */
37 MCHBAR32(0x5404) = IOMMU_BASE1 >> 32;
38 MCHBAR32(0x5400) = IOMMU_BASE1 | 1;
39 MCHBAR32(0x5414) = IOMMU_BASE2 >> 32;
40 MCHBAR32(0x5410) = IOMMU_BASE2 | 1;
41
42 /* lock policies */
43 write32((void *)(IOMMU_BASE1 + 0xff0), 0x80000000);
44
45 const struct device *const azalia = pcidev_on_root(0x1b, 0);
46 if (azalia && azalia->enabled) {
47 write32((void *)(IOMMU_BASE2 + 0xff0), 0x20000000);
48 write32((void *)(IOMMU_BASE2 + 0xff0), 0xa0000000);
49 } else {
50 write32((void *)(IOMMU_BASE2 + 0xff0), 0x80000000);
51 }
52}
53
54static void enable_pam_region(void)
55{
56 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
57 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
58 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
59 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
60 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
61 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
62 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
63}
64
Stefan Reinauer00636b02012-04-04 00:08:51 +020065static void sandybridge_setup_bars(void)
66{
Stefan Reinauer00636b02012-04-04 00:08:51 +020067 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
68 /* Set up all hardcoded northbridge BARs */
69 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
70 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4, (0LL+DEFAULT_EPBAR) >> 32);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080071 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1);
72 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, (0LL+(uintptr_t)DEFAULT_MCHBAR) >> 32);
73 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1);
74 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4, (0LL+(uintptr_t)DEFAULT_DMIBAR) >> 32);
Stefan Reinauer00636b02012-04-04 00:08:51 +020075
Patrick Rudolph90050712019-03-25 09:53:23 +010076 printk(BIOS_DEBUG, " done\n");
Stefan Reinauer00636b02012-04-04 00:08:51 +020077}
78
79static void sandybridge_setup_graphics(void)
80{
81 u32 reg32;
82 u16 reg16;
83 u8 reg8;
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +020084 u8 gfxsize;
Stefan Reinauer00636b02012-04-04 00:08:51 +020085
86 reg16 = pci_read_config16(PCI_DEV(0,2,0), PCI_DEVICE_ID);
87 switch (reg16) {
88 case 0x0102: /* GT1 Desktop */
89 case 0x0106: /* GT1 Mobile */
90 case 0x010a: /* GT1 Server */
91 case 0x0112: /* GT2 Desktop */
92 case 0x0116: /* GT2 Mobile */
93 case 0x0122: /* GT2 Desktop >=1.3GHz */
94 case 0x0126: /* GT2 Mobile >=1.3GHz */
Patrick Rudolph03a88d32015-07-05 13:29:41 +020095 case 0x0152: /* IvyBridge */
Stefan Reinauer816e9d12013-01-14 10:25:43 -080096 case 0x0156: /* IvyBridge */
Damien Zammita10bde92014-10-23 13:29:32 +110097 case 0x0162: /* IvyBridge */
Stefan Reinauer816e9d12013-01-14 10:25:43 -080098 case 0x0166: /* IvyBridge */
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +000099 case 0x016a: /* IvyBridge */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200100 break;
101 default:
102 printk(BIOS_DEBUG, "Graphics not supported by this CPU/chipset.\n");
103 return;
104 }
105
106 printk(BIOS_DEBUG, "Initializing Graphics...\n");
107
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +0200108 if (get_option(&gfxsize, "gfx_uma_size") != CB_SUCCESS) {
109 /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
110 gfxsize = 0;
111 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200112 reg16 = pci_read_config16(PCI_DEV(0,0,0), GGC);
113 reg16 &= ~0x00f8;
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +0200114 reg16 |= (gfxsize + 1) << 3;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200115 /* Program GTT memory by setting GGC[9:8] = 2MB */
116 reg16 &= ~0x0300;
117 reg16 |= 2 << 8;
118 /* Enable VGA decode */
119 reg16 &= ~0x0002;
120 pci_write_config16(PCI_DEV(0,0,0), GGC, reg16);
121
122 /* Enable 256MB aperture */
123 reg8 = pci_read_config8(PCI_DEV(0, 2, 0), MSAC);
124 reg8 &= ~0x06;
125 reg8 |= 0x02;
126 pci_write_config8(PCI_DEV(0, 2, 0), MSAC, reg8);
127
128 /* Erratum workarounds */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200129 reg32 = MCHBAR32(0x5f00);
130 reg32 |= (1 << 9)|(1 << 10);
131 MCHBAR32(0x5f00) = reg32;
132
133 /* Enable SA Clock Gating */
134 reg32 = MCHBAR32(0x5f00);
135 MCHBAR32(0x5f00) = reg32 | 1;
136
137 /* GPU RC6 workaround for sighting 366252 */
138 reg32 = MCHBAR32(0x5d14);
139 reg32 |= (1 << 31);
140 MCHBAR32(0x5d14) = reg32;
141
142 /* VLW */
143 reg32 = MCHBAR32(0x6120);
144 reg32 &= ~(1 << 0);
145 MCHBAR32(0x6120) = reg32;
146
147 reg32 = MCHBAR32(0x5418);
148 reg32 |= (1 << 4) | (1 << 5);
149 MCHBAR32(0x5418) = reg32;
150}
151
Patrick Rudolphe4f9d5c2015-10-15 11:09:15 +0200152static void start_peg_link_training(void)
153{
154 u32 tmp;
155 u32 deven;
156
157 /* PEG on IvyBridge+ needs a special startup sequence.
158 * As the MRC has its own initialization code skip it. */
159 if (((pci_read_config16(PCI_DEV(0, 0, 0), PCI_DEVICE_ID) &
160 BASE_REV_MASK) != BASE_REV_IVB) ||
Julius Wernercd49cce2019-03-05 16:53:33 -0800161 CONFIG(HAVE_MRC))
Patrick Rudolphe4f9d5c2015-10-15 11:09:15 +0200162 return;
163
164 deven = pci_read_config32(PCI_DEV(0, 0, 0), DEVEN);
165
166 if (deven & DEVEN_PEG10) {
167 tmp = pci_read_config32(PCI_DEV(0, 1, 0), 0xC24) & ~(1 << 16);
168 pci_write_config32(PCI_DEV(0, 1, 0), 0xC24, tmp | (1 << 5));
169 }
170
171 if (deven & DEVEN_PEG11) {
172 tmp = pci_read_config32(PCI_DEV(0, 1, 1), 0xC24) & ~(1 << 16);
173 pci_write_config32(PCI_DEV(0, 1, 1), 0xC24, tmp | (1 << 5));
174 }
175
176 if (deven & DEVEN_PEG12) {
177 tmp = pci_read_config32(PCI_DEV(0, 1, 2), 0xC24) & ~(1 << 16);
178 pci_write_config32(PCI_DEV(0, 1, 2), 0xC24, tmp | (1 << 5));
179 }
180
181 if (deven & DEVEN_PEG60) {
182 tmp = pci_read_config32(PCI_DEV(0, 6, 0), 0xC24) & ~(1 << 16);
183 pci_write_config32(PCI_DEV(0, 6, 0), 0xC24, tmp | (1 << 5));
184 }
185}
186
Patrick Rudolph2cdb65d2019-03-24 18:08:43 +0100187void systemagent_early_init(void)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200188{
189 u32 capid0_a;
Patrick Rudolph2a510a72015-07-28 07:51:10 +0200190 u32 deven;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200191 u8 reg8;
192
193 /* Device ID Override Enable should be done very early */
194 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4);
195 if (capid0_a & (1 << 10)) {
Patrick Rudolph74203de2017-11-20 11:57:01 +0100196 const size_t is_mobile = get_platform_type() == PLATFORM_MOBILE;
197
Stefan Reinauer00636b02012-04-04 00:08:51 +0200198 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3);
199 reg8 &= ~7; /* Clear 2:0 */
200
Patrick Rudolph74203de2017-11-20 11:57:01 +0100201 if (is_mobile)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200202 reg8 |= 1; /* Set bit 0 */
203
204 pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8);
205 }
206
207 /* Setup all BARs required for early PCIe and raminit */
208 sandybridge_setup_bars();
209
Patrick Rudolph2cdb65d2019-03-24 18:08:43 +0100210 /* Set C0000-FFFFF to access RAM on both reads and writes */
211 enable_pam_region();
212
Nico Huberbb9469c2015-10-21 11:49:23 +0200213 /* Setup IOMMU BARs */
Patrick Rudolph2cdb65d2019-03-24 18:08:43 +0100214 systemagent_vtd_init();
Nico Huberbb9469c2015-10-21 11:49:23 +0200215
Patrick Rudolph2a510a72015-07-28 07:51:10 +0200216 /* Device Enable, don't touch PEG bits */
217 deven = pci_read_config32(PCI_DEV(0, 0, 0), DEVEN) | DEVEN_IGD;
218 pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, deven);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200219
220 sandybridge_setup_graphics();
Patrick Rudolphe4f9d5c2015-10-15 11:09:15 +0200221
222 /* Write magic value to start PEG link training.
223 * This should be done in PCI device enumeration, but
224 * the PCIe specification requires to wait at least 100msec
225 * after reset for devices to come up.
226 * As we don't want to increase boot time, enable it early and
227 * assume the PEG is up as soon as PCI enumeration starts.
228 * TODO: use time stamps to ensure the timings are met */
229 start_peg_link_training();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200230}
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200231
232void northbridge_romstage_finalize(int s3resume)
233{
234 MCHBAR16(SSKPD) = 0xCAFE;
235
Aaron Durbin77e13992016-11-29 17:43:04 -0600236 romstage_handoff_init(s3resume);
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200237}