blob: 6aad4a381fa856a84afc40abd34daebfb38a1fc6 [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
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.
Aaron Durbin76c37002012-10-30 09:03:43 -050015 */
16
17#include <stdint.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050018#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020019#include <device/mmio.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050020#include <device/pci_def.h>
Tristan Corrick334be322018-12-17 22:10:21 +130021#include <device/pci_ops.h>
Elyes HAOUASc27014b2019-06-23 11:11:53 +020022
Aaron Durbin76c37002012-10-30 09:03:43 -050023#include "haswell.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050024
Tristan Corrick334be322018-12-17 22:10:21 +130025static bool peg_hidden[3];
26
Aaron Durbin76c37002012-10-30 09:03:43 -050027static void haswell_setup_bars(void)
28{
Aaron Durbin76c37002012-10-30 09:03:43 -050029 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);
33 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1);
34 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, (0LL+DEFAULT_MCHBAR) >> 32);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080035 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);
Aaron Durbin76c37002012-10-30 09:03:43 -050037
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
47 printk(BIOS_DEBUG, " done.\n");
Aaron Durbin76c37002012-10-30 09:03:43 -050048}
49
Tristan Corrick334be322018-12-17 22:10:21 +130050static void haswell_setup_igd(void)
Aaron Durbin76c37002012-10-30 09:03:43 -050051{
Tristan Corrickc5d367b2018-12-17 22:10:07 +130052 bool igd_enabled;
53 u16 ggc;
Aaron Durbin76c37002012-10-30 09:03:43 -050054 u8 reg8;
55
Tristan Corrick334be322018-12-17 22:10:21 +130056 printk(BIOS_DEBUG, "Initializing IGD...\n");
Aaron Durbin76c37002012-10-30 09:03:43 -050057
Tristan Corrickc5d367b2018-12-17 22:10:07 +130058 igd_enabled = !!(pci_read_config32(PCI_DEV(0, 0, 0), DEVEN)
59 & DEVEN_D2EN);
60
61 ggc = pci_read_config16(PCI_DEV(0, 0, 0), GGC);
62 ggc &= ~0x3f8;
63 if (igd_enabled) {
64 ggc |= GGC_GTT_2MB | GGC_IGD_MEM_IN_32MB_UNITS(1);
65 ggc &= ~GGC_DISABLE_VGA_IO_DECODE;
66 } else {
67 ggc |= GGC_GTT_0MB | GGC_IGD_MEM_IN_32MB_UNITS(0) |
68 GGC_DISABLE_VGA_IO_DECODE;
69 }
70 pci_write_config16(PCI_DEV(0, 0, 0), GGC, ggc);
71
72 if (!igd_enabled) {
73 printk(BIOS_DEBUG, "IGD is disabled.\n");
74 return;
75 }
Aaron Durbin76c37002012-10-30 09:03:43 -050076
77 /* Enable 256MB aperture */
78 reg8 = pci_read_config8(PCI_DEV(0, 2, 0), MSAC);
79 reg8 &= ~0x06;
80 reg8 |= 0x02;
81 pci_write_config8(PCI_DEV(0, 2, 0), MSAC, reg8);
Tristan Corrickc5d367b2018-12-17 22:10:07 +130082}
83
Tristan Corrick334be322018-12-17 22:10:21 +130084static void start_peg2_link_training(const pci_devfn_t dev)
85{
86 u32 mask;
87
88 switch (dev) {
89 case PCI_DEV(0, 1, 2):
90 mask = DEVEN_D1F2EN;
91 break;
92 case PCI_DEV(0, 1, 1):
93 mask = DEVEN_D1F1EN;
94 break;
95 case PCI_DEV(0, 1, 0):
96 mask = DEVEN_D1F0EN;
97 break;
98 default:
99 printk(BIOS_ERR, "Link training tried on a non-PEG device!\n");
100 return;
101 }
102
103 pci_update_config32(dev, 0xc24, ~(1 << 16), 1 << 5);
Chris Morgan2806ec92020-02-05 10:51:46 -0600104 printk(BIOS_DEBUG, "Started PEG1%d link training.\n", PCI_FUNC(PCI_DEV2DEVFN(dev)));
Tristan Corrick334be322018-12-17 22:10:21 +1300105
106 /*
107 * The PEG device is hidden while the MRC runs. This is because the
108 * MRC makes configurations that are not ideal if it sees a VGA
109 * device in a PEG slot, and it locks registers preventing changes
110 * to these configurations.
111 */
112 pci_update_config32(PCI_DEV(0, 0, 0), DEVEN, ~mask, 0);
Chris Morgan2806ec92020-02-05 10:51:46 -0600113 peg_hidden[PCI_FUNC(PCI_DEV2DEVFN(dev))] = true;
114 printk(BIOS_DEBUG, "Temporarily hiding PEG1%d.\n", PCI_FUNC(PCI_DEV2DEVFN(dev)));
Tristan Corrick334be322018-12-17 22:10:21 +1300115}
116
117void haswell_unhide_peg(void)
118{
119 u32 deven = pci_read_config32(PCI_DEV(0, 0, 0), DEVEN);
120
121 for (u8 fn = 0; fn <= 2; fn++) {
122 if (peg_hidden[fn]) {
123 deven |= DEVEN_D1F0EN >> fn;
124 peg_hidden[fn] = false;
125 printk(BIOS_DEBUG, "Unhiding PEG1%d.\n", fn);
126 }
127 }
128
129 pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, deven);
130}
131
132static void haswell_setup_peg(void)
133{
134 u32 deven = pci_read_config32(PCI_DEV(0, 0, 0), DEVEN);
135
136 if (deven & DEVEN_D1F2EN)
137 start_peg2_link_training(PCI_DEV(0, 1, 2));
138 if (deven & DEVEN_D1F1EN)
139 start_peg2_link_training(PCI_DEV(0, 1, 1));
140 if (deven & DEVEN_D1F0EN)
141 start_peg2_link_training(PCI_DEV(0, 1, 0));
142}
143
Tristan Corrickc5d367b2018-12-17 22:10:07 +1300144static void haswell_setup_misc(void)
145{
146 u32 reg32;
Aaron Durbin76c37002012-10-30 09:03:43 -0500147
148 /* Erratum workarounds */
149 reg32 = MCHBAR32(0x5f00);
150 reg32 |= (1 << 9)|(1 << 10);
151 MCHBAR32(0x5f00) = reg32;
152
153 /* Enable SA Clock Gating */
154 reg32 = MCHBAR32(0x5f00);
155 MCHBAR32(0x5f00) = reg32 | 1;
156
157 /* GPU RC6 workaround for sighting 366252 */
158 reg32 = MCHBAR32(0x5d14);
Ryan Salsamendib9bc2572017-07-04 13:35:06 -0700159 reg32 |= (1UL << 31);
Aaron Durbin76c37002012-10-30 09:03:43 -0500160 MCHBAR32(0x5d14) = reg32;
161
162 /* VLW */
163 reg32 = MCHBAR32(0x6120);
164 reg32 &= ~(1 << 0);
165 MCHBAR32(0x6120) = reg32;
166
167 reg32 = MCHBAR32(0x5418);
168 reg32 |= (1 << 4) | (1 << 5);
169 MCHBAR32(0x5418) = reg32;
170}
171
Matt DeVilliera51e3792018-03-04 01:44:15 -0600172static void haswell_setup_iommu(void)
173{
174 const u32 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), CAPID0_A);
175
176 if (capid0_a & VTD_DISABLE)
177 return;
178
179 /* setup BARs: zeroize top 32 bits; set enable bit */
180 MCHBAR32(GFXVTBAR + 4) = GFXVT_BASE_ADDRESS >> 32;
181 MCHBAR32(GFXVTBAR) = GFXVT_BASE_ADDRESS | 1;
182 MCHBAR32(VTVC0BAR + 4) = VTVC0_BASE_ADDRESS >> 32;
183 MCHBAR32(VTVC0BAR) = VTVC0_BASE_ADDRESS | 1;
184
185 /* set L3HIT2PEND_DIS, lock GFXVTBAR policy cfg registers */
186 u32 reg32;
187 reg32 = read32((void *)(GFXVT_BASE_ADDRESS + ARCHDIS));
188 write32((void *)(GFXVT_BASE_ADDRESS + ARCHDIS),
189 reg32 | DMAR_LCKDN | L3HIT2PEND_DIS);
190 /* clear SPCAPCTRL */
191 reg32 = read32((void *)(VTVC0_BASE_ADDRESS + ARCHDIS)) & ~SPCAPCTRL;
192 /* set GLBIOTLBINV, GLBCTXTINV; lock VTVC0BAR policy cfg registers */
193 write32((void *)(VTVC0_BASE_ADDRESS + ARCHDIS),
194 reg32 | DMAR_LCKDN | GLBIOTLBINV | GLBCTXTINV);
195}
196
Aaron Durbin76c37002012-10-30 09:03:43 -0500197void haswell_early_initialization(int chipset_type)
198{
Aaron Durbin76c37002012-10-30 09:03:43 -0500199 /* Setup all BARs required for early PCIe and raminit */
200 haswell_setup_bars();
201
Matt DeVilliera51e3792018-03-04 01:44:15 -0600202 /* Setup IOMMU BARs */
203 haswell_setup_iommu();
204
Tristan Corrick334be322018-12-17 22:10:21 +1300205 haswell_setup_peg();
206 haswell_setup_igd();
Tristan Corrickc5d367b2018-12-17 22:10:07 +1300207
208 haswell_setup_misc();
Aaron Durbin76c37002012-10-30 09:03:43 -0500209}