blob: a3eaba963f2c880e0522b0eb7a244dddbd7ff52e [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.
Stefan Reinauer8e073822012-04-04 00:07:22 +020015 */
16
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pciexp.h>
21#include <device/pci_ids.h>
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010022#include <southbridge/intel/common/pciehp.h>
Patrick Rudolph604f6982017-06-07 09:46:52 +020023#include <assert.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020024#include "pch.h"
25
Stefan Reinauer8e073822012-04-04 00:07:22 +020026static void pch_pcie_pm_early(struct device *dev)
27{
28 u16 link_width_p0, link_width_p4;
29 u8 slot_power_limit = 10; /* 10W for x1 */
30 u32 reg32;
31 u8 reg8;
32
Duncan Laurie4aca5d72012-04-27 10:58:22 -070033 reg32 = RCBA32(RPC);
34
35 /* Port 0-3 link aggregation from PCIEPCS1[1:0] soft strap */
36 switch (reg32 & 3) {
37 case 3:
38 link_width_p0 = 4;
39 break;
40 case 1:
41 case 2:
42 link_width_p0 = 2;
43 break;
44 case 0:
45 default:
46 link_width_p0 = 1;
47 }
48
49 /* Port 4-7 link aggregation from PCIEPCS2[1:0] soft strap */
50 switch ((reg32 >> 2) & 3) {
51 case 3:
52 link_width_p4 = 4;
53 break;
54 case 1:
55 case 2:
56 link_width_p4 = 2;
57 break;
58 case 0:
59 default:
60 link_width_p4 = 1;
61 }
Stefan Reinauer8e073822012-04-04 00:07:22 +020062
63 /* Enable dynamic clock gating where needed */
64 reg8 = pci_read_config8(dev, 0xe1);
65 switch (PCI_FUNC(dev->path.pci.devfn)) {
66 case 0: /* Port 0 */
67 if (link_width_p0 == 4)
68 slot_power_limit = 40; /* 40W for x4 */
69 else if (link_width_p0 == 2)
70 slot_power_limit = 20; /* 20W for x2 */
Duncan Laurie4aca5d72012-04-27 10:58:22 -070071 reg8 |= 0x3f;
72 break;
Stefan Reinauer8e073822012-04-04 00:07:22 +020073 case 4: /* Port 4 */
74 if (link_width_p4 == 4)
75 slot_power_limit = 40; /* 40W for x4 */
76 else if (link_width_p4 == 2)
77 slot_power_limit = 20; /* 20W for x2 */
78 reg8 |= 0x3f;
79 break;
80 case 1: /* Port 1 only if Port 0 is x1 */
81 if (link_width_p0 == 1)
82 reg8 |= 0x3;
83 break;
84 case 2: /* Port 2 only if Port 0 is x1 or x2 */
85 case 3: /* Port 3 only if Port 0 is x1 or x2 */
86 if (link_width_p0 <= 2)
87 reg8 |= 0x3;
88 break;
89 case 5: /* Port 5 only if Port 4 is x1 */
90 if (link_width_p4 == 1)
91 reg8 |= 0x3;
92 break;
93 case 6: /* Port 7 only if Port 4 is x1 or x2 */
94 case 7: /* Port 7 only if Port 4 is x1 or x2 */
95 if (link_width_p4 <= 2)
96 reg8 |= 0x3;
97 break;
98 }
99 pci_write_config8(dev, 0xe1, reg8);
100
101 /* Set 0xE8[0] = 1 */
102 reg32 = pci_read_config32(dev, 0xe8);
103 reg32 |= 1;
104 pci_write_config32(dev, 0xe8, reg32);
105
106 /* Adjust Common Clock exit latency */
107 reg32 = pci_read_config32(dev, 0xd8);
108 reg32 &= ~(1 << 17);
109 reg32 |= (1 << 16) | (1 << 15);
110 reg32 &= ~(1 << 31); /* Disable PME# SCI for native PME handling */
111 pci_write_config32(dev, 0xd8, reg32);
112
113 /* Adjust ASPM L1 exit latency */
114 reg32 = pci_read_config32(dev, 0x4c);
115 reg32 &= ~((1 << 17) | (1 << 16) | (1 << 15));
116 if (RCBA32(0x2320) & (1 << 16)) {
117 /* If RCBA+2320[15]=1 set ASPM L1 to 8-16us */
118 reg32 |= (1 << 17);
119 } else {
120 /* Else set ASPM L1 to 2-4us */
121 reg32 |= (1 << 16);
122 }
123 pci_write_config32(dev, 0x4c, reg32);
124
125 /* Set slot power limit as configured above */
126 reg32 = pci_read_config32(dev, 0x54);
127 reg32 &= ~((1 << 15) | (1 << 16)); /* 16:15 = Slot power scale */
128 reg32 &= ~(0xff << 7); /* 14:7 = Slot power limit */
129 reg32 |= (slot_power_limit << 7);
130 pci_write_config32(dev, 0x54, reg32);
131}
132
133static void pch_pcie_pm_late(struct device *dev)
134{
Marc Jones4adc8cd2012-10-31 16:24:37 -0600135 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
136 enum aspm_type apmc = 0;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200137 u32 reg32;
138
139 /* Set 0x314 = 0x743a361b */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300140 pci_write_config32(dev, 0x314, 0x743a361b);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200141
142 /* Set 0x318[31:16] = 0x1414 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300143 reg32 = pci_read_config32(dev, 0x318);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200144 reg32 &= 0x0000ffff;
145 reg32 |= 0x14140000;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300146 pci_write_config32(dev, 0x318, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200147
148 /* Set 0x324[5] = 1 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300149 reg32 = pci_read_config32(dev, 0x324);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200150 reg32 |= (1 << 5);
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300151 pci_write_config32(dev, 0x324, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200152
153 /* Set 0x330[7:0] = 0x40 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300154 reg32 = pci_read_config32(dev, 0x330);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200155 reg32 &= ~(0xff);
156 reg32 |= 0x40;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300157 pci_write_config32(dev, 0x330, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200158
159 /* Set 0x33C[24:0] = 0x854c74 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300160 reg32 = pci_read_config32(dev, 0x33c);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200161 reg32 &= 0xff000000;
162 reg32 |= 0x00854c74;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300163 pci_write_config32(dev, 0x33c, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200164
165 /* No IO-APIC, Disable EOI forwarding */
166 reg32 = pci_read_config32(dev, 0xd4);
167 reg32 |= (1 << 1);
168 pci_write_config32(dev, 0xd4, reg32);
169
Marc Jones4adc8cd2012-10-31 16:24:37 -0600170 /* Check for a rootport ASPM override */
171 switch (PCI_FUNC(dev->path.pci.devfn)) {
172 case 0:
173 apmc = config->pcie_aspm_f0;
174 break;
175 case 1:
176 apmc = config->pcie_aspm_f1;
177 break;
178 case 2:
179 apmc = config->pcie_aspm_f2;
180 break;
181 case 3:
182 apmc = config->pcie_aspm_f3;
183 break;
184 case 4:
185 apmc = config->pcie_aspm_f4;
186 break;
187 case 5:
188 apmc = config->pcie_aspm_f5;
189 break;
190 case 6:
191 apmc = config->pcie_aspm_f6;
192 break;
193 case 7:
194 apmc = config->pcie_aspm_f7;
195 break;
196 }
197
198 /* Setup the override or get the real ASPM setting */
199 if (apmc) {
200 reg32 = pci_read_config32(dev, 0xd4);
201 reg32 |= (apmc << 2) | (1 << 4);
202 pci_write_config32(dev, 0xd4, reg32);
203 } else {
204 apmc = pci_read_config32(dev, 0x50) & 3;
205 }
Stefan Reinauer8e073822012-04-04 00:07:22 +0200206
207 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
208 if (apmc == PCIE_ASPM_BOTH) {
209 reg32 = pci_read_config32(dev, 0xe8);
210 reg32 |= (1 << 1);
211 pci_write_config32(dev, 0xe8, reg32);
212 }
213}
214
215static void pci_init(struct device *dev)
216{
217 u16 reg16;
218 u32 reg32;
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100219 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200220
221 printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n");
222
223 /* Enable Bus Master */
224 reg32 = pci_read_config32(dev, PCI_COMMAND);
225 reg32 |= PCI_COMMAND_MASTER;
226 pci_write_config32(dev, PCI_COMMAND, reg32);
227
228 /* Set Cache Line Size to 0x10 */
229 // This has no effect but the OS might expect it
230 pci_write_config8(dev, 0x0c, 0x10);
231
232 reg16 = pci_read_config16(dev, 0x3e);
233 reg16 &= ~(1 << 0); /* disable parity error response */
234 // reg16 &= ~(1 << 1); /* disable SERR */
235 reg16 |= (1 << 2); /* ISA enable */
236 pci_write_config16(dev, 0x3e, reg16);
237
238#ifdef EVEN_MORE_DEBUG
239 reg32 = pci_read_config32(dev, 0x20);
240 printk(BIOS_SPEW, " MBL = 0x%08x\n", reg32);
241 reg32 = pci_read_config32(dev, 0x24);
242 printk(BIOS_SPEW, " PMBL = 0x%08x\n", reg32);
243 reg32 = pci_read_config32(dev, 0x28);
244 printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", reg32);
245 reg32 = pci_read_config32(dev, 0x2c);
246 printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", reg32);
247#endif
248
249 /* Clear errors in status registers */
250 reg16 = pci_read_config16(dev, 0x06);
251 //reg16 |= 0xf900;
252 pci_write_config16(dev, 0x06, reg16);
253
254 reg16 = pci_read_config16(dev, 0x1e);
255 //reg16 |= 0xf900;
256 pci_write_config16(dev, 0x1e, reg16);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100257
258 /* Enable expresscard hotplug events. */
259 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
260 pci_write_config32(dev, 0xd8,
261 pci_read_config32(dev, 0xd8)
262 | (1 << 30));
263 pci_write_config16(dev, 0x42, 0x142);
264 }
Stefan Reinauer8e073822012-04-04 00:07:22 +0200265}
266
267static void pch_pcie_enable(device_t dev)
268{
269 /* Power Management init before enumeration */
270 pch_pcie_pm_early(dev);
271}
272
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200273static void pch_pciexp_scan_bridge(device_t dev)
Marc Jones4adc8cd2012-10-31 16:24:37 -0600274{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100275 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
Marc Jones4adc8cd2012-10-31 16:24:37 -0600276
277 /* Normal PCIe Scan */
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200278 pciexp_scan_bridge(dev);
Marc Jones4adc8cd2012-10-31 16:24:37 -0600279
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100280 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
281 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
282 }
283
Marc Jones4adc8cd2012-10-31 16:24:37 -0600284 /* Late Power Management init after bridge device enumeration */
285 pch_pcie_pm_late(dev);
Marc Jones4adc8cd2012-10-31 16:24:37 -0600286}
287
Patrick Rudolph604f6982017-06-07 09:46:52 +0200288static const char *pch_pcie_acpi_name(device_t dev)
289{
290 ASSERT(dev);
291
292 if (PCI_SLOT(dev->path.pci.devfn) == 0x1c) {
293 static const char *names[] = { "RP01",
294 "RP02",
295 "RP03",
296 "RP04",
297 "RP05",
298 "RP06",
299 "RP07",
300 "RP08"};
301
302 return names[PCI_FUNC(dev->path.pci.devfn)];
303 }
304
305 return NULL;
306}
307
Stefan Reinauer8e073822012-04-04 00:07:22 +0200308static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device)
309{
310 /* NOTE: This is not the default position! */
311 if (!vendor || !device) {
312 pci_write_config32(dev, 0x94,
313 pci_read_config32(dev, 0));
314 } else {
315 pci_write_config32(dev, 0x94,
316 ((device & 0xffff) << 16) | (vendor & 0xffff));
317 }
318}
319
320static struct pci_operations pci_ops = {
321 .set_subsystem = pcie_set_subsystem,
322};
323
324static struct device_operations device_ops = {
325 .read_resources = pci_bus_read_resources,
326 .set_resources = pci_dev_set_resources,
327 .enable_resources = pci_bus_enable_resources,
328 .init = pci_init,
329 .enable = pch_pcie_enable,
Marc Jones4adc8cd2012-10-31 16:24:37 -0600330 .scan_bus = pch_pciexp_scan_bridge,
Patrick Rudolph604f6982017-06-07 09:46:52 +0200331 .acpi_name = pch_pcie_acpi_name,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200332 .ops_pci = &pci_ops,
333};
334
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700335static const unsigned short pci_device_ids[] = { 0x1c10, 0x1c12, 0x1c14, 0x1c16,
336 0x1c18, 0x1c1a, 0x1c1c, 0x1c1e,
337 0x1e10, 0x1e12, 0x1e14, 0x1e16,
338 0x1e18, 0x1e1a, 0x1e1c, 0x1e1e,
339 0 };
Stefan Reinauer8e073822012-04-04 00:07:22 +0200340
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700341static const struct pci_driver pch_pcie __pci_driver = {
342 .ops = &device_ops,
343 .vendor = PCI_VENDOR_ID_INTEL,
344 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200345};