blob: 779f29befd08fa892ab2ca8a291f1ff8310d1377 [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älkkia969ed32016-06-15 06:08:15 +030021#include <arch/acpi.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020022#include <device/pci_def.h>
Duncan Laurief4d36232012-06-23 16:37:45 -070023#include <elog.h>
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +020024#include <cbmem.h>
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +020025#include <pc80/mc146818rtc.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020026#include "sandybridge.h"
Stefan Reinauer00636b02012-04-04 00:08:51 +020027
28static void sandybridge_setup_bars(void)
29{
30 /* Setting up Southbridge. In the northbridge code. */
31 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080032 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, (uintptr_t)DEFAULT_RCBA | 1);
Stefan Reinauer00636b02012-04-04 00:08:51 +020033
34 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
35 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
36
37 printk(BIOS_DEBUG, " done.\n");
38
39 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
40 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
41 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
42 printk(BIOS_DEBUG, " done.\n");
43
44 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
45 /* Set up all hardcoded northbridge BARs */
46 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
47 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4, (0LL+DEFAULT_EPBAR) >> 32);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080048 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1);
49 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, (0LL+(uintptr_t)DEFAULT_MCHBAR) >> 32);
50 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1);
51 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4, (0LL+(uintptr_t)DEFAULT_DMIBAR) >> 32);
Stefan Reinauer00636b02012-04-04 00:08:51 +020052
53 /* Set C0000-FFFFF to access RAM on both reads and writes */
54 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
55 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
56 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
57 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
58 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
59 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
60 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
61
Duncan Laurief4d36232012-06-23 16:37:45 -070062#if CONFIG_ELOG_BOOT_COUNT
63 /* Increment Boot Counter for non-S3 resume */
64 if ((inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) &&
65 ((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) != SLP_TYP_S3)
66 boot_count_increment();
67#endif
68
Stefan Reinauer00636b02012-04-04 00:08:51 +020069 printk(BIOS_DEBUG, " done.\n");
Duncan Laurie9c4c6ab2012-06-29 15:38:02 -070070
71#if CONFIG_ELOG_BOOT_COUNT
72 /* Increment Boot Counter except when resuming from S3 */
73 if ((inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) &&
74 ((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3)
75 return;
76 boot_count_increment();
77#endif
Stefan Reinauer00636b02012-04-04 00:08:51 +020078}
79
80static void sandybridge_setup_graphics(void)
81{
82 u32 reg32;
83 u16 reg16;
84 u8 reg8;
Vladimir Serbinenko5fc04d12014-08-03 01:59:38 +020085 u8 gfxsize;
Stefan Reinauer00636b02012-04-04 00:08:51 +020086
87 reg16 = pci_read_config16(PCI_DEV(0,2,0), PCI_DEVICE_ID);
88 switch (reg16) {
89 case 0x0102: /* GT1 Desktop */
90 case 0x0106: /* GT1 Mobile */
91 case 0x010a: /* GT1 Server */
92 case 0x0112: /* GT2 Desktop */
93 case 0x0116: /* GT2 Mobile */
94 case 0x0122: /* GT2 Desktop >=1.3GHz */
95 case 0x0126: /* GT2 Mobile >=1.3GHz */
Patrick Rudolph03a88d32015-07-05 13:29:41 +020096 case 0x0152: /* IvyBridge */
Stefan Reinauer816e9d12013-01-14 10:25:43 -080097 case 0x0156: /* IvyBridge */
Damien Zammita10bde92014-10-23 13:29:32 +110098 case 0x0162: /* IvyBridge */
Stefan Reinauer816e9d12013-01-14 10:25:43 -080099 case 0x0166: /* 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) ||
161 IS_ENABLED(CONFIG_HAVE_MRC))
162 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
Stefan Reinauer00636b02012-04-04 00:08:51 +0200187void sandybridge_early_initialization(int chipset_type)
188{
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)) {
196 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3);
197 reg8 &= ~7; /* Clear 2:0 */
198
199 if (chipset_type == SANDYBRIDGE_MOBILE)
200 reg8 |= 1; /* Set bit 0 */
201
202 pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8);
203 }
204
205 /* Setup all BARs required for early PCIe and raminit */
206 sandybridge_setup_bars();
207
Nico Huberbb9469c2015-10-21 11:49:23 +0200208 /* Setup IOMMU BARs */
209 sandybridge_init_iommu();
210
Patrick Rudolph2a510a72015-07-28 07:51:10 +0200211 /* Device Enable, don't touch PEG bits */
212 deven = pci_read_config32(PCI_DEV(0, 0, 0), DEVEN) | DEVEN_IGD;
213 pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, deven);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200214
215 sandybridge_setup_graphics();
Patrick Rudolphe4f9d5c2015-10-15 11:09:15 +0200216
217 /* Write magic value to start PEG link training.
218 * This should be done in PCI device enumeration, but
219 * the PCIe specification requires to wait at least 100msec
220 * after reset for devices to come up.
221 * As we don't want to increase boot time, enable it early and
222 * assume the PEG is up as soon as PCI enumeration starts.
223 * TODO: use time stamps to ensure the timings are met */
224 start_peg_link_training();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200225}
Vladimir Serbinenkoc845b432014-09-05 03:37:44 +0200226
227void northbridge_romstage_finalize(int s3resume)
228{
229 MCHBAR16(SSKPD) = 0xCAFE;
230
231#if CONFIG_HAVE_ACPI_RESUME
232 /* If there is no high memory area, we didn't boot before, so
233 * this is not a resume. In that case we just create the cbmem toc.
234 */
235
236 *(u32 *)CBMEM_BOOT_MODE = 0;
237 *(u32 *)CBMEM_RESUME_BACKUP = 0;
238
239 if (s3resume) {
240 void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
241 if (resume_backup_memory) {
242 *(u32 *)CBMEM_BOOT_MODE = 2;
243 *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory;
244 }
245 /* Magic for S3 resume */
246 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d);
247 } else {
248 pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe);
249 }
250#endif
251}