blob: d688f5b5a1a161e1421b79b3dfbdf6fdc8e728c2 [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauer00636b02012-04-04 00:08:51 +020019 */
20
21#include <stdint.h>
22#include <stdlib.h>
23#include <console/console.h>
24#include <arch/io.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020025#include <device/pci_def.h>
Duncan Laurief4d36232012-06-23 16:37:45 -070026#include <elog.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...");
33 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1);
34
35 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
36 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
37
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);
49 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
50 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, (0LL+DEFAULT_MCHBAR) >> 32);
Stefan Reinauer00636b02012-04-04 00:08:51 +020051 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1);
52 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4, (0LL+DEFAULT_DMIBAR) >> 32);
53
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
Duncan Laurief4d36232012-06-23 16:37:45 -070063#if CONFIG_ELOG_BOOT_COUNT
64 /* 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
72#if CONFIG_ELOG_BOOT_COUNT
73 /* 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;
86
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 */
Stefan Reinauer816e9d12013-01-14 10:25:43 -080096 case 0x0156: /* IvyBridge */
97 case 0x0166: /* IvyBridge */
Stefan Reinauer00636b02012-04-04 00:08:51 +020098 break;
99 default:
100 printk(BIOS_DEBUG, "Graphics not supported by this CPU/chipset.\n");
101 return;
102 }
103
104 printk(BIOS_DEBUG, "Initializing Graphics...\n");
105
106 /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
107 reg16 = pci_read_config16(PCI_DEV(0,0,0), GGC);
108 reg16 &= ~0x00f8;
109 reg16 |= 1 << 3;
110 /* Program GTT memory by setting GGC[9:8] = 2MB */
111 reg16 &= ~0x0300;
112 reg16 |= 2 << 8;
113 /* Enable VGA decode */
114 reg16 &= ~0x0002;
115 pci_write_config16(PCI_DEV(0,0,0), GGC, reg16);
116
117 /* Enable 256MB aperture */
118 reg8 = pci_read_config8(PCI_DEV(0, 2, 0), MSAC);
119 reg8 &= ~0x06;
120 reg8 |= 0x02;
121 pci_write_config8(PCI_DEV(0, 2, 0), MSAC, reg8);
122
123 /* Erratum workarounds */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200124 reg32 = MCHBAR32(0x5f00);
125 reg32 |= (1 << 9)|(1 << 10);
126 MCHBAR32(0x5f00) = reg32;
127
128 /* Enable SA Clock Gating */
129 reg32 = MCHBAR32(0x5f00);
130 MCHBAR32(0x5f00) = reg32 | 1;
131
132 /* GPU RC6 workaround for sighting 366252 */
133 reg32 = MCHBAR32(0x5d14);
134 reg32 |= (1 << 31);
135 MCHBAR32(0x5d14) = reg32;
136
137 /* VLW */
138 reg32 = MCHBAR32(0x6120);
139 reg32 &= ~(1 << 0);
140 MCHBAR32(0x6120) = reg32;
141
142 reg32 = MCHBAR32(0x5418);
143 reg32 |= (1 << 4) | (1 << 5);
144 MCHBAR32(0x5418) = reg32;
145}
146
147void sandybridge_early_initialization(int chipset_type)
148{
149 u32 capid0_a;
150 u8 reg8;
151
152 /* Device ID Override Enable should be done very early */
153 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4);
154 if (capid0_a & (1 << 10)) {
155 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3);
156 reg8 &= ~7; /* Clear 2:0 */
157
158 if (chipset_type == SANDYBRIDGE_MOBILE)
159 reg8 |= 1; /* Set bit 0 */
160
161 pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8);
162 }
163
164 /* Setup all BARs required for early PCIe and raminit */
165 sandybridge_setup_bars();
166
167 /* Device Enable */
168 pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, DEVEN_HOST | DEVEN_IGD);
169
170 sandybridge_setup_graphics();
171}