blob: ff20c4483370370a0a2184e05b3fcd86fe44e464 [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
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdint.h>
22#include <stdlib.h>
23#include <console/console.h>
24#include <arch/io.h>
25#include <arch/romcc_io.h>
26#include <device/pci_def.h>
27#include "sandybridge.h"
28#include "pcie_config.c"
29
30static void sandybridge_setup_bars(void)
31{
32 /* Setting up Southbridge. In the northbridge code. */
33 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
34 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1);
35
36 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
37 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */
38
39 printk(BIOS_DEBUG, " done.\n");
40
41 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
42 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
43 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
44 printk(BIOS_DEBUG, " done.\n");
45
46 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
47 /* Set up all hardcoded northbridge BARs */
48 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
49 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4, (0LL+DEFAULT_EPBAR) >> 32);
50 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
51 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, (0LL+DEFAULT_MCHBAR) >> 32);
52 pci_write_config32(PCI_DEV(0, 0x00, 0), PCIEXBAR, DEFAULT_PCIEXBAR | 5); /* 64MB - busses 0-63 */
53 pci_write_config32(PCI_DEV(0, 0x00, 0), PCIEXBAR + 4, (0LL+DEFAULT_PCIEXBAR) >> 32);
54 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1);
55 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4, (0LL+DEFAULT_DMIBAR) >> 32);
56
57 /* Set C0000-FFFFF to access RAM on both reads and writes */
58 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30);
59 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33);
60 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33);
61 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33);
62 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33);
63 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33);
64 pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33);
65
66 printk(BIOS_DEBUG, " done.\n");
Duncan Laurie9c4c6ab2012-06-29 15:38:02 -070067
68#if CONFIG_ELOG_BOOT_COUNT
69 /* Increment Boot Counter except when resuming from S3 */
70 if ((inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) &&
71 ((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3)
72 return;
73 boot_count_increment();
74#endif
Stefan Reinauer00636b02012-04-04 00:08:51 +020075}
76
77static void sandybridge_setup_graphics(void)
78{
79 u32 reg32;
80 u16 reg16;
81 u8 reg8;
82
83 reg16 = pci_read_config16(PCI_DEV(0,2,0), PCI_DEVICE_ID);
84 switch (reg16) {
85 case 0x0102: /* GT1 Desktop */
86 case 0x0106: /* GT1 Mobile */
87 case 0x010a: /* GT1 Server */
88 case 0x0112: /* GT2 Desktop */
89 case 0x0116: /* GT2 Mobile */
90 case 0x0122: /* GT2 Desktop >=1.3GHz */
91 case 0x0126: /* GT2 Mobile >=1.3GHz */
92 case 0x0166: /* IvyBridge ??? */
93 break;
94 default:
95 printk(BIOS_DEBUG, "Graphics not supported by this CPU/chipset.\n");
96 return;
97 }
98
99 printk(BIOS_DEBUG, "Initializing Graphics...\n");
100
101 /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
102 reg16 = pci_read_config16(PCI_DEV(0,0,0), GGC);
103 reg16 &= ~0x00f8;
104 reg16 |= 1 << 3;
105 /* Program GTT memory by setting GGC[9:8] = 2MB */
106 reg16 &= ~0x0300;
107 reg16 |= 2 << 8;
108 /* Enable VGA decode */
109 reg16 &= ~0x0002;
110 pci_write_config16(PCI_DEV(0,0,0), GGC, reg16);
111
112 /* Enable 256MB aperture */
113 reg8 = pci_read_config8(PCI_DEV(0, 2, 0), MSAC);
114 reg8 &= ~0x06;
115 reg8 |= 0x02;
116 pci_write_config8(PCI_DEV(0, 2, 0), MSAC, reg8);
117
118 /* Erratum workarounds */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200119 reg32 = MCHBAR32(0x5f00);
120 reg32 |= (1 << 9)|(1 << 10);
121 MCHBAR32(0x5f00) = reg32;
122
123 /* Enable SA Clock Gating */
124 reg32 = MCHBAR32(0x5f00);
125 MCHBAR32(0x5f00) = reg32 | 1;
126
127 /* GPU RC6 workaround for sighting 366252 */
128 reg32 = MCHBAR32(0x5d14);
129 reg32 |= (1 << 31);
130 MCHBAR32(0x5d14) = reg32;
131
132 /* VLW */
133 reg32 = MCHBAR32(0x6120);
134 reg32 &= ~(1 << 0);
135 MCHBAR32(0x6120) = reg32;
136
137 reg32 = MCHBAR32(0x5418);
138 reg32 |= (1 << 4) | (1 << 5);
139 MCHBAR32(0x5418) = reg32;
140}
141
142void sandybridge_early_initialization(int chipset_type)
143{
144 u32 capid0_a;
145 u8 reg8;
146
147 /* Device ID Override Enable should be done very early */
148 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4);
149 if (capid0_a & (1 << 10)) {
150 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3);
151 reg8 &= ~7; /* Clear 2:0 */
152
153 if (chipset_type == SANDYBRIDGE_MOBILE)
154 reg8 |= 1; /* Set bit 0 */
155
156 pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8);
157 }
158
159 /* Setup all BARs required for early PCIe and raminit */
160 sandybridge_setup_bars();
161
162 /* Device Enable */
163 pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, DEVEN_HOST | DEVEN_IGD);
164
165 sandybridge_setup_graphics();
166}