blob: 4769dd53d09ffaaa25ae93cead77f949bba5af34 [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>
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010026#include <southbridge/intel/common/pciehp.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020027#include "pch.h"
28
Stefan Reinauer8e073822012-04-04 00:07:22 +020029static void pch_pcie_pm_early(struct device *dev)
30{
31 u16 link_width_p0, link_width_p4;
32 u8 slot_power_limit = 10; /* 10W for x1 */
33 u32 reg32;
34 u8 reg8;
35
Duncan Laurie4aca5d72012-04-27 10:58:22 -070036 reg32 = RCBA32(RPC);
37
38 /* Port 0-3 link aggregation from PCIEPCS1[1:0] soft strap */
39 switch (reg32 & 3) {
40 case 3:
41 link_width_p0 = 4;
42 break;
43 case 1:
44 case 2:
45 link_width_p0 = 2;
46 break;
47 case 0:
48 default:
49 link_width_p0 = 1;
50 }
51
52 /* Port 4-7 link aggregation from PCIEPCS2[1:0] soft strap */
53 switch ((reg32 >> 2) & 3) {
54 case 3:
55 link_width_p4 = 4;
56 break;
57 case 1:
58 case 2:
59 link_width_p4 = 2;
60 break;
61 case 0:
62 default:
63 link_width_p4 = 1;
64 }
Stefan Reinauer8e073822012-04-04 00:07:22 +020065
66 /* Enable dynamic clock gating where needed */
67 reg8 = pci_read_config8(dev, 0xe1);
68 switch (PCI_FUNC(dev->path.pci.devfn)) {
69 case 0: /* Port 0 */
70 if (link_width_p0 == 4)
71 slot_power_limit = 40; /* 40W for x4 */
72 else if (link_width_p0 == 2)
73 slot_power_limit = 20; /* 20W for x2 */
Duncan Laurie4aca5d72012-04-27 10:58:22 -070074 reg8 |= 0x3f;
75 break;
Stefan Reinauer8e073822012-04-04 00:07:22 +020076 case 4: /* Port 4 */
77 if (link_width_p4 == 4)
78 slot_power_limit = 40; /* 40W for x4 */
79 else if (link_width_p4 == 2)
80 slot_power_limit = 20; /* 20W for x2 */
81 reg8 |= 0x3f;
82 break;
83 case 1: /* Port 1 only if Port 0 is x1 */
84 if (link_width_p0 == 1)
85 reg8 |= 0x3;
86 break;
87 case 2: /* Port 2 only if Port 0 is x1 or x2 */
88 case 3: /* Port 3 only if Port 0 is x1 or x2 */
89 if (link_width_p0 <= 2)
90 reg8 |= 0x3;
91 break;
92 case 5: /* Port 5 only if Port 4 is x1 */
93 if (link_width_p4 == 1)
94 reg8 |= 0x3;
95 break;
96 case 6: /* Port 7 only if Port 4 is x1 or x2 */
97 case 7: /* Port 7 only if Port 4 is x1 or x2 */
98 if (link_width_p4 <= 2)
99 reg8 |= 0x3;
100 break;
101 }
102 pci_write_config8(dev, 0xe1, reg8);
103
104 /* Set 0xE8[0] = 1 */
105 reg32 = pci_read_config32(dev, 0xe8);
106 reg32 |= 1;
107 pci_write_config32(dev, 0xe8, reg32);
108
109 /* Adjust Common Clock exit latency */
110 reg32 = pci_read_config32(dev, 0xd8);
111 reg32 &= ~(1 << 17);
112 reg32 |= (1 << 16) | (1 << 15);
113 reg32 &= ~(1 << 31); /* Disable PME# SCI for native PME handling */
114 pci_write_config32(dev, 0xd8, reg32);
115
116 /* Adjust ASPM L1 exit latency */
117 reg32 = pci_read_config32(dev, 0x4c);
118 reg32 &= ~((1 << 17) | (1 << 16) | (1 << 15));
119 if (RCBA32(0x2320) & (1 << 16)) {
120 /* If RCBA+2320[15]=1 set ASPM L1 to 8-16us */
121 reg32 |= (1 << 17);
122 } else {
123 /* Else set ASPM L1 to 2-4us */
124 reg32 |= (1 << 16);
125 }
126 pci_write_config32(dev, 0x4c, reg32);
127
128 /* Set slot power limit as configured above */
129 reg32 = pci_read_config32(dev, 0x54);
130 reg32 &= ~((1 << 15) | (1 << 16)); /* 16:15 = Slot power scale */
131 reg32 &= ~(0xff << 7); /* 14:7 = Slot power limit */
132 reg32 |= (slot_power_limit << 7);
133 pci_write_config32(dev, 0x54, reg32);
134}
135
136static void pch_pcie_pm_late(struct device *dev)
137{
Marc Jones4adc8cd2012-10-31 16:24:37 -0600138 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
139 enum aspm_type apmc = 0;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200140 u32 reg32;
141
142 /* Set 0x314 = 0x743a361b */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300143 pci_write_config32(dev, 0x314, 0x743a361b);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200144
145 /* Set 0x318[31:16] = 0x1414 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300146 reg32 = pci_read_config32(dev, 0x318);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200147 reg32 &= 0x0000ffff;
148 reg32 |= 0x14140000;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300149 pci_write_config32(dev, 0x318, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200150
151 /* Set 0x324[5] = 1 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300152 reg32 = pci_read_config32(dev, 0x324);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200153 reg32 |= (1 << 5);
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300154 pci_write_config32(dev, 0x324, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200155
156 /* Set 0x330[7:0] = 0x40 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300157 reg32 = pci_read_config32(dev, 0x330);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200158 reg32 &= ~(0xff);
159 reg32 |= 0x40;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300160 pci_write_config32(dev, 0x330, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200161
162 /* Set 0x33C[24:0] = 0x854c74 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300163 reg32 = pci_read_config32(dev, 0x33c);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200164 reg32 &= 0xff000000;
165 reg32 |= 0x00854c74;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300166 pci_write_config32(dev, 0x33c, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200167
168 /* No IO-APIC, Disable EOI forwarding */
169 reg32 = pci_read_config32(dev, 0xd4);
170 reg32 |= (1 << 1);
171 pci_write_config32(dev, 0xd4, reg32);
172
Marc Jones4adc8cd2012-10-31 16:24:37 -0600173 /* Check for a rootport ASPM override */
174 switch (PCI_FUNC(dev->path.pci.devfn)) {
175 case 0:
176 apmc = config->pcie_aspm_f0;
177 break;
178 case 1:
179 apmc = config->pcie_aspm_f1;
180 break;
181 case 2:
182 apmc = config->pcie_aspm_f2;
183 break;
184 case 3:
185 apmc = config->pcie_aspm_f3;
186 break;
187 case 4:
188 apmc = config->pcie_aspm_f4;
189 break;
190 case 5:
191 apmc = config->pcie_aspm_f5;
192 break;
193 case 6:
194 apmc = config->pcie_aspm_f6;
195 break;
196 case 7:
197 apmc = config->pcie_aspm_f7;
198 break;
199 }
200
201 /* Setup the override or get the real ASPM setting */
202 if (apmc) {
203 reg32 = pci_read_config32(dev, 0xd4);
204 reg32 |= (apmc << 2) | (1 << 4);
205 pci_write_config32(dev, 0xd4, reg32);
206 } else {
207 apmc = pci_read_config32(dev, 0x50) & 3;
208 }
Stefan Reinauer8e073822012-04-04 00:07:22 +0200209
210 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
211 if (apmc == PCIE_ASPM_BOTH) {
212 reg32 = pci_read_config32(dev, 0xe8);
213 reg32 |= (1 << 1);
214 pci_write_config32(dev, 0xe8, reg32);
215 }
216}
217
218static void pci_init(struct device *dev)
219{
220 u16 reg16;
221 u32 reg32;
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100222 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200223
224 printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n");
225
226 /* Enable Bus Master */
227 reg32 = pci_read_config32(dev, PCI_COMMAND);
228 reg32 |= PCI_COMMAND_MASTER;
229 pci_write_config32(dev, PCI_COMMAND, reg32);
230
231 /* Set Cache Line Size to 0x10 */
232 // This has no effect but the OS might expect it
233 pci_write_config8(dev, 0x0c, 0x10);
234
235 reg16 = pci_read_config16(dev, 0x3e);
236 reg16 &= ~(1 << 0); /* disable parity error response */
237 // reg16 &= ~(1 << 1); /* disable SERR */
238 reg16 |= (1 << 2); /* ISA enable */
239 pci_write_config16(dev, 0x3e, reg16);
240
241#ifdef EVEN_MORE_DEBUG
242 reg32 = pci_read_config32(dev, 0x20);
243 printk(BIOS_SPEW, " MBL = 0x%08x\n", reg32);
244 reg32 = pci_read_config32(dev, 0x24);
245 printk(BIOS_SPEW, " PMBL = 0x%08x\n", reg32);
246 reg32 = pci_read_config32(dev, 0x28);
247 printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", reg32);
248 reg32 = pci_read_config32(dev, 0x2c);
249 printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", reg32);
250#endif
251
252 /* Clear errors in status registers */
253 reg16 = pci_read_config16(dev, 0x06);
254 //reg16 |= 0xf900;
255 pci_write_config16(dev, 0x06, reg16);
256
257 reg16 = pci_read_config16(dev, 0x1e);
258 //reg16 |= 0xf900;
259 pci_write_config16(dev, 0x1e, reg16);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100260
261 /* Enable expresscard hotplug events. */
262 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
263 pci_write_config32(dev, 0xd8,
264 pci_read_config32(dev, 0xd8)
265 | (1 << 30));
266 pci_write_config16(dev, 0x42, 0x142);
267 }
Stefan Reinauer8e073822012-04-04 00:07:22 +0200268}
269
270static void pch_pcie_enable(device_t dev)
271{
272 /* Power Management init before enumeration */
273 pch_pcie_pm_early(dev);
274}
275
Marc Jones4adc8cd2012-10-31 16:24:37 -0600276static unsigned int pch_pciexp_scan_bridge(device_t dev, unsigned int max)
277{
278 unsigned int ret;
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100279 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
Marc Jones4adc8cd2012-10-31 16:24:37 -0600280
281 /* Normal PCIe Scan */
282 ret = pciexp_scan_bridge(dev, max);
283
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100284 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
285 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
286 }
287
Marc Jones4adc8cd2012-10-31 16:24:37 -0600288 /* Late Power Management init after bridge device enumeration */
289 pch_pcie_pm_late(dev);
290
291 return ret;
292}
293
Stefan Reinauer8e073822012-04-04 00:07:22 +0200294static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device)
295{
296 /* NOTE: This is not the default position! */
297 if (!vendor || !device) {
298 pci_write_config32(dev, 0x94,
299 pci_read_config32(dev, 0));
300 } else {
301 pci_write_config32(dev, 0x94,
302 ((device & 0xffff) << 16) | (vendor & 0xffff));
303 }
304}
305
306static struct pci_operations pci_ops = {
307 .set_subsystem = pcie_set_subsystem,
308};
309
310static struct device_operations device_ops = {
311 .read_resources = pci_bus_read_resources,
312 .set_resources = pci_dev_set_resources,
313 .enable_resources = pci_bus_enable_resources,
314 .init = pci_init,
315 .enable = pch_pcie_enable,
Marc Jones4adc8cd2012-10-31 16:24:37 -0600316 .scan_bus = pch_pciexp_scan_bridge,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200317 .ops_pci = &pci_ops,
318};
319
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700320static const unsigned short pci_device_ids[] = { 0x1c10, 0x1c12, 0x1c14, 0x1c16,
321 0x1c18, 0x1c1a, 0x1c1c, 0x1c1e,
322 0x1e10, 0x1e12, 0x1e14, 0x1e16,
323 0x1e18, 0x1e1a, 0x1e1c, 0x1e1e,
324 0 };
Stefan Reinauer8e073822012-04-04 00:07:22 +0200325
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700326static const struct pci_driver pch_pcie __pci_driver = {
327 .ops = &device_ops,
328 .vendor = PCI_VENDOR_ID_INTEL,
329 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200330};