blob: 01787f13a9f5d45db639aeeecdcd112f5af55f9d [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>
Kyösti Mälkkia969ed32016-06-15 06:08:15 +030022#include <arch/acpi.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020023#include <device/pci_def.h>
Duncan Laurief4d36232012-06-23 16:37:45 -070024#include <elog.h>
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +020025#include <pc80/mc146818rtc.h>
Kyösti Mälkkie39a8a92016-06-25 11:40:00 +030026#include <romstage_handoff.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020027#include "sandybridge.h"
Stefan Reinauer00636b02012-04-04 00:08:51 +020028
29static void sandybridge_setup_bars(void)
30{
31 /* Setting up Southbridge. In the northbridge code. */
32 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
Patrick Rudolph44526cd2017-05-03 18:49:28 +020033 pci_write_config32(PCH_LPC_DEV, RCBA, (uintptr_t)DEFAULT_RCBA | 1);
Stefan Reinauer00636b02012-04-04 00:08:51 +020034
Patrick Rudolph44526cd2017-05-03 18:49:28 +020035 pci_write_config32(PCH_LPC_DEV, PMBASE, DEFAULT_PMBASE | 1);
36 pci_write_config8(PCH_LPC_DEV, ACPI_CNTL, 0x80); /* Enable ACPI BAR */
Stefan Reinauer00636b02012-04-04 00:08:51 +020037
38 printk(BIOS_DEBUG, " done.\n");
39
40 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
41 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
42 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
43 printk(BIOS_DEBUG, " done.\n");
44
45 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
46 /* Set up all hardcoded northbridge BARs */
47 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
48 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4, (0LL+DEFAULT_EPBAR) >> 32);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080049 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1);
50 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, (0LL+(uintptr_t)DEFAULT_MCHBAR) >> 32);
51 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1);
52 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4, (0LL+(uintptr_t)DEFAULT_DMIBAR) >> 32);
Stefan Reinauer00636b02012-04-04 00:08:51 +020053
54 /* Set C0000-FFFFF to access RAM on both reads and writes */
55 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
56 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
57 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
58 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
59 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
60 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
61 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
62
Martin Roth33232602017-06-24 14:48:50 -060063#if IS_ENABLED(CONFIG_ELOG_BOOT_COUNT)
Duncan Laurief4d36232012-06-23 16:37:45 -070064 /* Increment Boot Counter for non-S3 resume */
65 if ((inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) &&
66 ((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) != SLP_TYP_S3)
67 boot_count_increment();
68#endif
69
Stefan Reinauer00636b02012-04-04 00:08:51 +020070 printk(BIOS_DEBUG, " done.\n");
Duncan Laurie9c4c6ab2012-06-29 15:38:02 -070071
Martin Roth33232602017-06-24 14:48:50 -060072#if IS_ENABLED(CONFIG_ELOG_BOOT_COUNT)
Duncan Laurie9c4c6ab2012-06-29 15:38:02 -070073 /* Increment Boot Counter except when resuming from S3 */
74 if ((inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) &&
75 ((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3)
76 return;
77 boot_count_increment();
78#endif
Stefan Reinauer00636b02012-04-04 00:08:51 +020079}
80
81static void sandybridge_setup_graphics(void)
82{
83 u32 reg32;
84 u16 reg16;
85 u8 reg8;
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +020086 u8 gfxsize;
Stefan Reinauer00636b02012-04-04 00:08:51 +020087
88 reg16 = pci_read_config16(PCI_DEV(0,2,0), PCI_DEVICE_ID);
89 switch (reg16) {
90 case 0x0102: /* GT1 Desktop */
91 case 0x0106: /* GT1 Mobile */
92 case 0x010a: /* GT1 Server */
93 case 0x0112: /* GT2 Desktop */
94 case 0x0116: /* GT2 Mobile */
95 case 0x0122: /* GT2 Desktop >=1.3GHz */
96 case 0x0126: /* GT2 Mobile >=1.3GHz */
Patrick Rudolph03a88d32015-07-05 13:29:41 +020097 case 0x0152: /* IvyBridge */
Stefan Reinauer816e9d12013-01-14 10:25:43 -080098 case 0x0156: /* IvyBridge */
Damien Zammita10bde92014-10-23 13:29:32 +110099 case 0x0162: /* IvyBridge */
Stefan Reinauer816e9d12013-01-14 10:25:43 -0800100 case 0x0166: /* IvyBridge */
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000101 case 0x016a: /* IvyBridge */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200102 break;
103 default:
104 printk(BIOS_DEBUG, "Graphics not supported by this CPU/chipset.\n");
105 return;
106 }
107
108 printk(BIOS_DEBUG, "Initializing Graphics...\n");
109
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +0200110 if (get_option(&gfxsize, "gfx_uma_size") != CB_SUCCESS) {
111 /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
112 gfxsize = 0;
113 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200114 reg16 = pci_read_config16(PCI_DEV(0,0,0), GGC);
115 reg16 &= ~0x00f8;
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +0200116 reg16 |= (gfxsize + 1) << 3;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200117 /* Program GTT memory by setting GGC[9:8] = 2MB */
118 reg16 &= ~0x0300;
119 reg16 |= 2 << 8;
120 /* Enable VGA decode */
121 reg16 &= ~0x0002;
122 pci_write_config16(PCI_DEV(0,0,0), GGC, reg16);
123
124 /* Enable 256MB aperture */
125 reg8 = pci_read_config8(PCI_DEV(0, 2, 0), MSAC);
126 reg8 &= ~0x06;
127 reg8 |= 0x02;
128 pci_write_config8(PCI_DEV(0, 2, 0), MSAC, reg8);
129
130 /* Erratum workarounds */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200131 reg32 = MCHBAR32(0x5f00);
132 reg32 |= (1 << 9)|(1 << 10);
133 MCHBAR32(0x5f00) = reg32;
134
135 /* Enable SA Clock Gating */
136 reg32 = MCHBAR32(0x5f00);
137 MCHBAR32(0x5f00) = reg32 | 1;
138
139 /* GPU RC6 workaround for sighting 366252 */
140 reg32 = MCHBAR32(0x5d14);
141 reg32 |= (1 << 31);
142 MCHBAR32(0x5d14) = reg32;
143
144 /* VLW */
145 reg32 = MCHBAR32(0x6120);
146 reg32 &= ~(1 << 0);
147 MCHBAR32(0x6120) = reg32;
148
149 reg32 = MCHBAR32(0x5418);
150 reg32 |= (1 << 4) | (1 << 5);
151 MCHBAR32(0x5418) = reg32;
152}
153
Patrick Rudolphe4f9d5c2015-10-15 11:09:15 +0200154static void start_peg_link_training(void)
155{
156 u32 tmp;
157 u32 deven;
158
159 /* PEG on IvyBridge+ needs a special startup sequence.
160 * As the MRC has its own initialization code skip it. */
161 if (((pci_read_config16(PCI_DEV(0, 0, 0), PCI_DEVICE_ID) &
162 BASE_REV_MASK) != BASE_REV_IVB) ||
163 IS_ENABLED(CONFIG_HAVE_MRC))
164 return;
165
166 deven = pci_read_config32(PCI_DEV(0, 0, 0), DEVEN);
167
168 if (deven & DEVEN_PEG10) {
169 tmp = pci_read_config32(PCI_DEV(0, 1, 0), 0xC24) & ~(1 << 16);
170 pci_write_config32(PCI_DEV(0, 1, 0), 0xC24, tmp | (1 << 5));
171 }
172
173 if (deven & DEVEN_PEG11) {
174 tmp = pci_read_config32(PCI_DEV(0, 1, 1), 0xC24) & ~(1 << 16);
175 pci_write_config32(PCI_DEV(0, 1, 1), 0xC24, tmp | (1 << 5));
176 }
177
178 if (deven & DEVEN_PEG12) {
179 tmp = pci_read_config32(PCI_DEV(0, 1, 2), 0xC24) & ~(1 << 16);
180 pci_write_config32(PCI_DEV(0, 1, 2), 0xC24, tmp | (1 << 5));
181 }
182
183 if (deven & DEVEN_PEG60) {
184 tmp = pci_read_config32(PCI_DEV(0, 6, 0), 0xC24) & ~(1 << 16);
185 pci_write_config32(PCI_DEV(0, 6, 0), 0xC24, tmp | (1 << 5));
186 }
187}
188
Patrick Rudolph74203de2017-11-20 11:57:01 +0100189void sandybridge_early_initialization(void)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200190{
191 u32 capid0_a;
Patrick Rudolph2a510a72015-07-28 07:51:10 +0200192 u32 deven;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200193 u8 reg8;
194
195 /* Device ID Override Enable should be done very early */
196 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4);
197 if (capid0_a & (1 << 10)) {
Patrick Rudolph74203de2017-11-20 11:57:01 +0100198 const size_t is_mobile = get_platform_type() == PLATFORM_MOBILE;
199
Stefan Reinauer00636b02012-04-04 00:08:51 +0200200 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3);
201 reg8 &= ~7; /* Clear 2:0 */
202
Patrick Rudolph74203de2017-11-20 11:57:01 +0100203 if (is_mobile)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200204 reg8 |= 1; /* Set bit 0 */
205
206 pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8);
207 }
208
209 /* Setup all BARs required for early PCIe and raminit */
210 sandybridge_setup_bars();
211
Nico Huberbb9469c2015-10-21 11:49:23 +0200212 /* Setup IOMMU BARs */
213 sandybridge_init_iommu();
214
Patrick Rudolph2a510a72015-07-28 07:51:10 +0200215 /* Device Enable, don't touch PEG bits */
216 deven = pci_read_config32(PCI_DEV(0, 0, 0), DEVEN) | DEVEN_IGD;
217 pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, deven);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200218
219 sandybridge_setup_graphics();
Patrick Rudolphe4f9d5c2015-10-15 11:09:15 +0200220
221 /* Write magic value to start PEG link training.
222 * This should be done in PCI device enumeration, but
223 * the PCIe specification requires to wait at least 100msec
224 * after reset for devices to come up.
225 * As we don't want to increase boot time, enable it early and
226 * assume the PEG is up as soon as PCI enumeration starts.
227 * TODO: use time stamps to ensure the timings are met */
228 start_peg_link_training();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200229}
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200230
231void northbridge_romstage_finalize(int s3resume)
232{
233 MCHBAR16(SSKPD) = 0xCAFE;
234
Aaron Durbin77e13992016-11-29 17:43:04 -0600235 romstage_handoff_init(s3resume);
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200236}