blob: 34aec3851b6a1227906bcbbc9297a6d5e8e55fca [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
5 * Copyright (C) 2011 Google Inc
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Stefan Reinauer00636b02012-04-04 00:08:51 +020015 */
16
17#include <stdint.h>
18#include <stdlib.h>
19#include <console/console.h>
20#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020022#include <device/pci_def.h>
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +020023#include <pc80/mc146818rtc.h>
Kyösti Mälkkie39a8a92016-06-25 11:40:00 +030024#include <romstage_handoff.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020025#include "sandybridge.h"
Stefan Reinauer00636b02012-04-04 00:08:51 +020026
27static void sandybridge_setup_bars(void)
28{
Stefan Reinauer00636b02012-04-04 00:08:51 +020029 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
30 /* Set up all hardcoded northbridge BARs */
31 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
32 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4, (0LL+DEFAULT_EPBAR) >> 32);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080033 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1);
34 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, (0LL+(uintptr_t)DEFAULT_MCHBAR) >> 32);
35 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1);
36 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4, (0LL+(uintptr_t)DEFAULT_DMIBAR) >> 32);
Stefan Reinauer00636b02012-04-04 00:08:51 +020037
38 /* Set C0000-FFFFF to access RAM on both reads and writes */
39 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
40 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
41 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
42 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
43 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
44 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
45 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
46
Patrick Rudolph90050712019-03-25 09:53:23 +010047 printk(BIOS_DEBUG, " done\n");
Stefan Reinauer00636b02012-04-04 00:08:51 +020048}
49
50static void sandybridge_setup_graphics(void)
51{
52 u32 reg32;
53 u16 reg16;
54 u8 reg8;
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +020055 u8 gfxsize;
Stefan Reinauer00636b02012-04-04 00:08:51 +020056
57 reg16 = pci_read_config16(PCI_DEV(0,2,0), PCI_DEVICE_ID);
58 switch (reg16) {
59 case 0x0102: /* GT1 Desktop */
60 case 0x0106: /* GT1 Mobile */
61 case 0x010a: /* GT1 Server */
62 case 0x0112: /* GT2 Desktop */
63 case 0x0116: /* GT2 Mobile */
64 case 0x0122: /* GT2 Desktop >=1.3GHz */
65 case 0x0126: /* GT2 Mobile >=1.3GHz */
Patrick Rudolph03a88d32015-07-05 13:29:41 +020066 case 0x0152: /* IvyBridge */
Stefan Reinauer816e9d12013-01-14 10:25:43 -080067 case 0x0156: /* IvyBridge */
Damien Zammita10bde92014-10-23 13:29:32 +110068 case 0x0162: /* IvyBridge */
Stefan Reinauer816e9d12013-01-14 10:25:43 -080069 case 0x0166: /* IvyBridge */
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +000070 case 0x016a: /* IvyBridge */
Stefan Reinauer00636b02012-04-04 00:08:51 +020071 break;
72 default:
73 printk(BIOS_DEBUG, "Graphics not supported by this CPU/chipset.\n");
74 return;
75 }
76
77 printk(BIOS_DEBUG, "Initializing Graphics...\n");
78
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +020079 if (get_option(&gfxsize, "gfx_uma_size") != CB_SUCCESS) {
80 /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
81 gfxsize = 0;
82 }
Stefan Reinauer00636b02012-04-04 00:08:51 +020083 reg16 = pci_read_config16(PCI_DEV(0,0,0), GGC);
84 reg16 &= ~0x00f8;
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +020085 reg16 |= (gfxsize + 1) << 3;
Stefan Reinauer00636b02012-04-04 00:08:51 +020086 /* Program GTT memory by setting GGC[9:8] = 2MB */
87 reg16 &= ~0x0300;
88 reg16 |= 2 << 8;
89 /* Enable VGA decode */
90 reg16 &= ~0x0002;
91 pci_write_config16(PCI_DEV(0,0,0), GGC, reg16);
92
93 /* Enable 256MB aperture */
94 reg8 = pci_read_config8(PCI_DEV(0, 2, 0), MSAC);
95 reg8 &= ~0x06;
96 reg8 |= 0x02;
97 pci_write_config8(PCI_DEV(0, 2, 0), MSAC, reg8);
98
99 /* Erratum workarounds */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200100 reg32 = MCHBAR32(0x5f00);
101 reg32 |= (1 << 9)|(1 << 10);
102 MCHBAR32(0x5f00) = reg32;
103
104 /* Enable SA Clock Gating */
105 reg32 = MCHBAR32(0x5f00);
106 MCHBAR32(0x5f00) = reg32 | 1;
107
108 /* GPU RC6 workaround for sighting 366252 */
109 reg32 = MCHBAR32(0x5d14);
110 reg32 |= (1 << 31);
111 MCHBAR32(0x5d14) = reg32;
112
113 /* VLW */
114 reg32 = MCHBAR32(0x6120);
115 reg32 &= ~(1 << 0);
116 MCHBAR32(0x6120) = reg32;
117
118 reg32 = MCHBAR32(0x5418);
119 reg32 |= (1 << 4) | (1 << 5);
120 MCHBAR32(0x5418) = reg32;
121}
122
Patrick Rudolphe4f9d5c2015-10-15 11:09:15 +0200123static void start_peg_link_training(void)
124{
125 u32 tmp;
126 u32 deven;
127
128 /* PEG on IvyBridge+ needs a special startup sequence.
129 * As the MRC has its own initialization code skip it. */
130 if (((pci_read_config16(PCI_DEV(0, 0, 0), PCI_DEVICE_ID) &
131 BASE_REV_MASK) != BASE_REV_IVB) ||
Julius Wernercd49cce2019-03-05 16:53:33 -0800132 CONFIG(HAVE_MRC))
Patrick Rudolphe4f9d5c2015-10-15 11:09:15 +0200133 return;
134
135 deven = pci_read_config32(PCI_DEV(0, 0, 0), DEVEN);
136
137 if (deven & DEVEN_PEG10) {
138 tmp = pci_read_config32(PCI_DEV(0, 1, 0), 0xC24) & ~(1 << 16);
139 pci_write_config32(PCI_DEV(0, 1, 0), 0xC24, tmp | (1 << 5));
140 }
141
142 if (deven & DEVEN_PEG11) {
143 tmp = pci_read_config32(PCI_DEV(0, 1, 1), 0xC24) & ~(1 << 16);
144 pci_write_config32(PCI_DEV(0, 1, 1), 0xC24, tmp | (1 << 5));
145 }
146
147 if (deven & DEVEN_PEG12) {
148 tmp = pci_read_config32(PCI_DEV(0, 1, 2), 0xC24) & ~(1 << 16);
149 pci_write_config32(PCI_DEV(0, 1, 2), 0xC24, tmp | (1 << 5));
150 }
151
152 if (deven & DEVEN_PEG60) {
153 tmp = pci_read_config32(PCI_DEV(0, 6, 0), 0xC24) & ~(1 << 16);
154 pci_write_config32(PCI_DEV(0, 6, 0), 0xC24, tmp | (1 << 5));
155 }
156}
157
Patrick Rudolph74203de2017-11-20 11:57:01 +0100158void sandybridge_early_initialization(void)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200159{
160 u32 capid0_a;
Patrick Rudolph2a510a72015-07-28 07:51:10 +0200161 u32 deven;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200162 u8 reg8;
163
164 /* Device ID Override Enable should be done very early */
165 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4);
166 if (capid0_a & (1 << 10)) {
Patrick Rudolph74203de2017-11-20 11:57:01 +0100167 const size_t is_mobile = get_platform_type() == PLATFORM_MOBILE;
168
Stefan Reinauer00636b02012-04-04 00:08:51 +0200169 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3);
170 reg8 &= ~7; /* Clear 2:0 */
171
Patrick Rudolph74203de2017-11-20 11:57:01 +0100172 if (is_mobile)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200173 reg8 |= 1; /* Set bit 0 */
174
175 pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8);
176 }
177
178 /* Setup all BARs required for early PCIe and raminit */
179 sandybridge_setup_bars();
180
Nico Huberbb9469c2015-10-21 11:49:23 +0200181 /* Setup IOMMU BARs */
182 sandybridge_init_iommu();
183
Patrick Rudolph2a510a72015-07-28 07:51:10 +0200184 /* Device Enable, don't touch PEG bits */
185 deven = pci_read_config32(PCI_DEV(0, 0, 0), DEVEN) | DEVEN_IGD;
186 pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, deven);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200187
188 sandybridge_setup_graphics();
Patrick Rudolphe4f9d5c2015-10-15 11:09:15 +0200189
190 /* Write magic value to start PEG link training.
191 * This should be done in PCI device enumeration, but
192 * the PCIe specification requires to wait at least 100msec
193 * after reset for devices to come up.
194 * As we don't want to increase boot time, enable it early and
195 * assume the PEG is up as soon as PCI enumeration starts.
196 * TODO: use time stamps to ensure the timings are met */
197 start_peg_link_training();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200198}
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200199
200void northbridge_romstage_finalize(int s3resume)
201{
202 MCHBAR16(SSKPD) = 0xCAFE;
203
Aaron Durbin77e13992016-11-29 17:43:04 -0600204 romstage_handoff_init(s3resume);
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200205}