blob: fadb43ff2b5f725fc4f557cbec6b046052906ae3 [file] [log] [blame]
Stefan Reinauer8e073822012-04-04 00:07:22 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * 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 Reinauer8e073822012-04-04 00:07:22 +020019 */
20
21#include <console/console.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pciexp.h>
25#include <device/pci_ids.h>
26#include "pch.h"
27
Stefan Reinauer8e073822012-04-04 00:07:22 +020028static void pch_pcie_pm_early(struct device *dev)
29{
30 u16 link_width_p0, link_width_p4;
31 u8 slot_power_limit = 10; /* 10W for x1 */
32 u32 reg32;
33 u8 reg8;
34
Duncan Laurie4aca5d72012-04-27 10:58:22 -070035 reg32 = RCBA32(RPC);
36
37 /* Port 0-3 link aggregation from PCIEPCS1[1:0] soft strap */
38 switch (reg32 & 3) {
39 case 3:
40 link_width_p0 = 4;
41 break;
42 case 1:
43 case 2:
44 link_width_p0 = 2;
45 break;
46 case 0:
47 default:
48 link_width_p0 = 1;
49 }
50
51 /* Port 4-7 link aggregation from PCIEPCS2[1:0] soft strap */
52 switch ((reg32 >> 2) & 3) {
53 case 3:
54 link_width_p4 = 4;
55 break;
56 case 1:
57 case 2:
58 link_width_p4 = 2;
59 break;
60 case 0:
61 default:
62 link_width_p4 = 1;
63 }
Stefan Reinauer8e073822012-04-04 00:07:22 +020064
65 /* Enable dynamic clock gating where needed */
66 reg8 = pci_read_config8(dev, 0xe1);
67 switch (PCI_FUNC(dev->path.pci.devfn)) {
68 case 0: /* Port 0 */
69 if (link_width_p0 == 4)
70 slot_power_limit = 40; /* 40W for x4 */
71 else if (link_width_p0 == 2)
72 slot_power_limit = 20; /* 20W for x2 */
Duncan Laurie4aca5d72012-04-27 10:58:22 -070073 reg8 |= 0x3f;
74 break;
Stefan Reinauer8e073822012-04-04 00:07:22 +020075 case 4: /* Port 4 */
76 if (link_width_p4 == 4)
77 slot_power_limit = 40; /* 40W for x4 */
78 else if (link_width_p4 == 2)
79 slot_power_limit = 20; /* 20W for x2 */
80 reg8 |= 0x3f;
81 break;
82 case 1: /* Port 1 only if Port 0 is x1 */
83 if (link_width_p0 == 1)
84 reg8 |= 0x3;
85 break;
86 case 2: /* Port 2 only if Port 0 is x1 or x2 */
87 case 3: /* Port 3 only if Port 0 is x1 or x2 */
88 if (link_width_p0 <= 2)
89 reg8 |= 0x3;
90 break;
91 case 5: /* Port 5 only if Port 4 is x1 */
92 if (link_width_p4 == 1)
93 reg8 |= 0x3;
94 break;
95 case 6: /* Port 7 only if Port 4 is x1 or x2 */
96 case 7: /* Port 7 only if Port 4 is x1 or x2 */
97 if (link_width_p4 <= 2)
98 reg8 |= 0x3;
99 break;
100 }
101 pci_write_config8(dev, 0xe1, reg8);
102
103 /* Set 0xE8[0] = 1 */
104 reg32 = pci_read_config32(dev, 0xe8);
105 reg32 |= 1;
106 pci_write_config32(dev, 0xe8, reg32);
107
108 /* Adjust Common Clock exit latency */
109 reg32 = pci_read_config32(dev, 0xd8);
110 reg32 &= ~(1 << 17);
111 reg32 |= (1 << 16) | (1 << 15);
112 reg32 &= ~(1 << 31); /* Disable PME# SCI for native PME handling */
113 pci_write_config32(dev, 0xd8, reg32);
114
115 /* Adjust ASPM L1 exit latency */
116 reg32 = pci_read_config32(dev, 0x4c);
117 reg32 &= ~((1 << 17) | (1 << 16) | (1 << 15));
118 if (RCBA32(0x2320) & (1 << 16)) {
119 /* If RCBA+2320[15]=1 set ASPM L1 to 8-16us */
120 reg32 |= (1 << 17);
121 } else {
122 /* Else set ASPM L1 to 2-4us */
123 reg32 |= (1 << 16);
124 }
125 pci_write_config32(dev, 0x4c, reg32);
126
127 /* Set slot power limit as configured above */
128 reg32 = pci_read_config32(dev, 0x54);
129 reg32 &= ~((1 << 15) | (1 << 16)); /* 16:15 = Slot power scale */
130 reg32 &= ~(0xff << 7); /* 14:7 = Slot power limit */
131 reg32 |= (slot_power_limit << 7);
132 pci_write_config32(dev, 0x54, reg32);
133}
134
135static void pch_pcie_pm_late(struct device *dev)
136{
Marc Jones4adc8cd2012-10-31 16:24:37 -0600137 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
138 enum aspm_type apmc = 0;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200139 u32 reg32;
140
141 /* Set 0x314 = 0x743a361b */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300142 pci_write_config32(dev, 0x314, 0x743a361b);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200143
144 /* Set 0x318[31:16] = 0x1414 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300145 reg32 = pci_read_config32(dev, 0x318);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200146 reg32 &= 0x0000ffff;
147 reg32 |= 0x14140000;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300148 pci_write_config32(dev, 0x318, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200149
150 /* Set 0x324[5] = 1 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300151 reg32 = pci_read_config32(dev, 0x324);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200152 reg32 |= (1 << 5);
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300153 pci_write_config32(dev, 0x324, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200154
155 /* Set 0x330[7:0] = 0x40 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300156 reg32 = pci_read_config32(dev, 0x330);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200157 reg32 &= ~(0xff);
158 reg32 |= 0x40;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300159 pci_write_config32(dev, 0x330, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200160
161 /* Set 0x33C[24:0] = 0x854c74 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300162 reg32 = pci_read_config32(dev, 0x33c);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200163 reg32 &= 0xff000000;
164 reg32 |= 0x00854c74;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300165 pci_write_config32(dev, 0x33c, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200166
167 /* No IO-APIC, Disable EOI forwarding */
168 reg32 = pci_read_config32(dev, 0xd4);
169 reg32 |= (1 << 1);
170 pci_write_config32(dev, 0xd4, reg32);
171
Marc Jones4adc8cd2012-10-31 16:24:37 -0600172 /* Check for a rootport ASPM override */
173 switch (PCI_FUNC(dev->path.pci.devfn)) {
174 case 0:
175 apmc = config->pcie_aspm_f0;
176 break;
177 case 1:
178 apmc = config->pcie_aspm_f1;
179 break;
180 case 2:
181 apmc = config->pcie_aspm_f2;
182 break;
183 case 3:
184 apmc = config->pcie_aspm_f3;
185 break;
186 case 4:
187 apmc = config->pcie_aspm_f4;
188 break;
189 case 5:
190 apmc = config->pcie_aspm_f5;
191 break;
192 case 6:
193 apmc = config->pcie_aspm_f6;
194 break;
195 case 7:
196 apmc = config->pcie_aspm_f7;
197 break;
198 }
199
200 /* Setup the override or get the real ASPM setting */
201 if (apmc) {
202 reg32 = pci_read_config32(dev, 0xd4);
203 reg32 |= (apmc << 2) | (1 << 4);
204 pci_write_config32(dev, 0xd4, reg32);
205 } else {
206 apmc = pci_read_config32(dev, 0x50) & 3;
207 }
Stefan Reinauer8e073822012-04-04 00:07:22 +0200208
209 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
210 if (apmc == PCIE_ASPM_BOTH) {
211 reg32 = pci_read_config32(dev, 0xe8);
212 reg32 |= (1 << 1);
213 pci_write_config32(dev, 0xe8, reg32);
214 }
215}
216
217static void pci_init(struct device *dev)
218{
219 u16 reg16;
220 u32 reg32;
221
222 printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n");
223
224 /* Enable Bus Master */
225 reg32 = pci_read_config32(dev, PCI_COMMAND);
226 reg32 |= PCI_COMMAND_MASTER;
227 pci_write_config32(dev, PCI_COMMAND, reg32);
228
229 /* Set Cache Line Size to 0x10 */
230 // This has no effect but the OS might expect it
231 pci_write_config8(dev, 0x0c, 0x10);
232
233 reg16 = pci_read_config16(dev, 0x3e);
234 reg16 &= ~(1 << 0); /* disable parity error response */
235 // reg16 &= ~(1 << 1); /* disable SERR */
236 reg16 |= (1 << 2); /* ISA enable */
237 pci_write_config16(dev, 0x3e, reg16);
238
239#ifdef EVEN_MORE_DEBUG
240 reg32 = pci_read_config32(dev, 0x20);
241 printk(BIOS_SPEW, " MBL = 0x%08x\n", reg32);
242 reg32 = pci_read_config32(dev, 0x24);
243 printk(BIOS_SPEW, " PMBL = 0x%08x\n", reg32);
244 reg32 = pci_read_config32(dev, 0x28);
245 printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", reg32);
246 reg32 = pci_read_config32(dev, 0x2c);
247 printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", reg32);
248#endif
249
250 /* Clear errors in status registers */
251 reg16 = pci_read_config16(dev, 0x06);
252 //reg16 |= 0xf900;
253 pci_write_config16(dev, 0x06, reg16);
254
255 reg16 = pci_read_config16(dev, 0x1e);
256 //reg16 |= 0xf900;
257 pci_write_config16(dev, 0x1e, reg16);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200258}
259
260static void pch_pcie_enable(device_t dev)
261{
262 /* Power Management init before enumeration */
263 pch_pcie_pm_early(dev);
264}
265
Marc Jones4adc8cd2012-10-31 16:24:37 -0600266static unsigned int pch_pciexp_scan_bridge(device_t dev, unsigned int max)
267{
268 unsigned int ret;
269
270 /* Normal PCIe Scan */
271 ret = pciexp_scan_bridge(dev, max);
272
273 /* Late Power Management init after bridge device enumeration */
274 pch_pcie_pm_late(dev);
275
276 return ret;
277}
278
Stefan Reinauer8e073822012-04-04 00:07:22 +0200279static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device)
280{
281 /* NOTE: This is not the default position! */
282 if (!vendor || !device) {
283 pci_write_config32(dev, 0x94,
284 pci_read_config32(dev, 0));
285 } else {
286 pci_write_config32(dev, 0x94,
287 ((device & 0xffff) << 16) | (vendor & 0xffff));
288 }
289}
290
291static struct pci_operations pci_ops = {
292 .set_subsystem = pcie_set_subsystem,
293};
294
295static struct device_operations device_ops = {
296 .read_resources = pci_bus_read_resources,
297 .set_resources = pci_dev_set_resources,
298 .enable_resources = pci_bus_enable_resources,
299 .init = pci_init,
300 .enable = pch_pcie_enable,
Marc Jones4adc8cd2012-10-31 16:24:37 -0600301 .scan_bus = pch_pciexp_scan_bridge,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200302 .ops_pci = &pci_ops,
303};
304
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700305static const unsigned short pci_device_ids[] = { 0x1c10, 0x1c12, 0x1c14, 0x1c16,
306 0x1c18, 0x1c1a, 0x1c1c, 0x1c1e,
307 0x1e10, 0x1e12, 0x1e14, 0x1e16,
308 0x1e18, 0x1e1a, 0x1e1c, 0x1e1e,
309 0 };
Stefan Reinauer8e073822012-04-04 00:07:22 +0200310
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700311static const struct pci_driver pch_pcie __pci_driver = {
312 .ops = &device_ops,
313 .vendor = PCI_VENDOR_ID_INTEL,
314 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200315};