blob: 739f6ce8a8406ce6e50bfd94de1c25f612340c5f [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>
Kyösti Mälkkidf128a52019-09-21 18:35:37 +030020#include <device/pci_def.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020022#include <device/pciexp.h>
23#include <device/pci_ids.h>
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010024#include <southbridge/intel/common/pciehp.h>
Patrick Rudolph604f6982017-06-07 09:46:52 +020025#include <assert.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030026
27#include "chip.h"
Stefan Reinauer8e073822012-04-04 00:07:22 +020028#include "pch.h"
29
Stefan Reinauer8e073822012-04-04 00:07:22 +020030static void pch_pcie_pm_early(struct device *dev)
31{
32 u16 link_width_p0, link_width_p4;
33 u8 slot_power_limit = 10; /* 10W for x1 */
34 u32 reg32;
35 u8 reg8;
36
Duncan Laurie4aca5d72012-04-27 10:58:22 -070037 reg32 = RCBA32(RPC);
38
39 /* Port 0-3 link aggregation from PCIEPCS1[1:0] soft strap */
40 switch (reg32 & 3) {
41 case 3:
42 link_width_p0 = 4;
43 break;
44 case 1:
45 case 2:
46 link_width_p0 = 2;
47 break;
48 case 0:
49 default:
50 link_width_p0 = 1;
51 }
52
53 /* Port 4-7 link aggregation from PCIEPCS2[1:0] soft strap */
54 switch ((reg32 >> 2) & 3) {
55 case 3:
56 link_width_p4 = 4;
57 break;
58 case 1:
59 case 2:
60 link_width_p4 = 2;
61 break;
62 case 0:
63 default:
64 link_width_p4 = 1;
65 }
Stefan Reinauer8e073822012-04-04 00:07:22 +020066
67 /* Enable dynamic clock gating where needed */
68 reg8 = pci_read_config8(dev, 0xe1);
69 switch (PCI_FUNC(dev->path.pci.devfn)) {
70 case 0: /* Port 0 */
71 if (link_width_p0 == 4)
72 slot_power_limit = 40; /* 40W for x4 */
73 else if (link_width_p0 == 2)
74 slot_power_limit = 20; /* 20W for x2 */
Duncan Laurie4aca5d72012-04-27 10:58:22 -070075 reg8 |= 0x3f;
76 break;
Stefan Reinauer8e073822012-04-04 00:07:22 +020077 case 4: /* Port 4 */
78 if (link_width_p4 == 4)
79 slot_power_limit = 40; /* 40W for x4 */
80 else if (link_width_p4 == 2)
81 slot_power_limit = 20; /* 20W for x2 */
82 reg8 |= 0x3f;
83 break;
84 case 1: /* Port 1 only if Port 0 is x1 */
85 if (link_width_p0 == 1)
86 reg8 |= 0x3;
87 break;
88 case 2: /* Port 2 only if Port 0 is x1 or x2 */
89 case 3: /* Port 3 only if Port 0 is x1 or x2 */
90 if (link_width_p0 <= 2)
91 reg8 |= 0x3;
92 break;
93 case 5: /* Port 5 only if Port 4 is x1 */
94 if (link_width_p4 == 1)
95 reg8 |= 0x3;
96 break;
97 case 6: /* Port 7 only if Port 4 is x1 or x2 */
98 case 7: /* Port 7 only if Port 4 is x1 or x2 */
99 if (link_width_p4 <= 2)
100 reg8 |= 0x3;
101 break;
102 }
103 pci_write_config8(dev, 0xe1, reg8);
104
105 /* Set 0xE8[0] = 1 */
106 reg32 = pci_read_config32(dev, 0xe8);
107 reg32 |= 1;
108 pci_write_config32(dev, 0xe8, reg32);
109
110 /* Adjust Common Clock exit latency */
111 reg32 = pci_read_config32(dev, 0xd8);
112 reg32 &= ~(1 << 17);
113 reg32 |= (1 << 16) | (1 << 15);
114 reg32 &= ~(1 << 31); /* Disable PME# SCI for native PME handling */
115 pci_write_config32(dev, 0xd8, reg32);
116
117 /* Adjust ASPM L1 exit latency */
118 reg32 = pci_read_config32(dev, 0x4c);
119 reg32 &= ~((1 << 17) | (1 << 16) | (1 << 15));
Patrick Rudolph4f8b1082019-07-14 11:54:58 +0200120 if (RCBA32(CIR9) & (1 << 16)) {
Stefan Reinauer8e073822012-04-04 00:07:22 +0200121 /* If RCBA+2320[15]=1 set ASPM L1 to 8-16us */
122 reg32 |= (1 << 17);
123 } else {
124 /* Else set ASPM L1 to 2-4us */
125 reg32 |= (1 << 16);
126 }
127 pci_write_config32(dev, 0x4c, reg32);
128
129 /* Set slot power limit as configured above */
130 reg32 = pci_read_config32(dev, 0x54);
131 reg32 &= ~((1 << 15) | (1 << 16)); /* 16:15 = Slot power scale */
132 reg32 &= ~(0xff << 7); /* 14:7 = Slot power limit */
133 reg32 |= (slot_power_limit << 7);
134 pci_write_config32(dev, 0x54, reg32);
135}
136
137static void pch_pcie_pm_late(struct device *dev)
138{
Marc Jones4adc8cd2012-10-31 16:24:37 -0600139 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
140 enum aspm_type apmc = 0;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200141 u32 reg32;
142
143 /* Set 0x314 = 0x743a361b */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300144 pci_write_config32(dev, 0x314, 0x743a361b);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200145
146 /* Set 0x318[31:16] = 0x1414 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300147 reg32 = pci_read_config32(dev, 0x318);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200148 reg32 &= 0x0000ffff;
149 reg32 |= 0x14140000;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300150 pci_write_config32(dev, 0x318, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200151
152 /* Set 0x324[5] = 1 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300153 reg32 = pci_read_config32(dev, 0x324);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200154 reg32 |= (1 << 5);
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300155 pci_write_config32(dev, 0x324, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200156
157 /* Set 0x330[7:0] = 0x40 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300158 reg32 = pci_read_config32(dev, 0x330);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200159 reg32 &= ~(0xff);
160 reg32 |= 0x40;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300161 pci_write_config32(dev, 0x330, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200162
163 /* Set 0x33C[24:0] = 0x854c74 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300164 reg32 = pci_read_config32(dev, 0x33c);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200165 reg32 &= 0xff000000;
166 reg32 |= 0x00854c74;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300167 pci_write_config32(dev, 0x33c, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200168
169 /* No IO-APIC, Disable EOI forwarding */
170 reg32 = pci_read_config32(dev, 0xd4);
171 reg32 |= (1 << 1);
172 pci_write_config32(dev, 0xd4, reg32);
173
Marc Jones4adc8cd2012-10-31 16:24:37 -0600174 /* Check for a rootport ASPM override */
175 switch (PCI_FUNC(dev->path.pci.devfn)) {
176 case 0:
177 apmc = config->pcie_aspm_f0;
178 break;
179 case 1:
180 apmc = config->pcie_aspm_f1;
181 break;
182 case 2:
183 apmc = config->pcie_aspm_f2;
184 break;
185 case 3:
186 apmc = config->pcie_aspm_f3;
187 break;
188 case 4:
189 apmc = config->pcie_aspm_f4;
190 break;
191 case 5:
192 apmc = config->pcie_aspm_f5;
193 break;
194 case 6:
195 apmc = config->pcie_aspm_f6;
196 break;
197 case 7:
198 apmc = config->pcie_aspm_f7;
199 break;
200 }
201
202 /* Setup the override or get the real ASPM setting */
203 if (apmc) {
204 reg32 = pci_read_config32(dev, 0xd4);
205 reg32 |= (apmc << 2) | (1 << 4);
206 pci_write_config32(dev, 0xd4, reg32);
207 } else {
208 apmc = pci_read_config32(dev, 0x50) & 3;
209 }
Stefan Reinauer8e073822012-04-04 00:07:22 +0200210
211 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
212 if (apmc == PCIE_ASPM_BOTH) {
213 reg32 = pci_read_config32(dev, 0xe8);
214 reg32 |= (1 << 1);
215 pci_write_config32(dev, 0xe8, reg32);
216 }
217}
218
219static void pci_init(struct device *dev)
220{
221 u16 reg16;
222 u32 reg32;
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100223 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200224
225 printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n");
226
227 /* Enable Bus Master */
228 reg32 = pci_read_config32(dev, PCI_COMMAND);
229 reg32 |= PCI_COMMAND_MASTER;
230 pci_write_config32(dev, PCI_COMMAND, reg32);
231
232 /* Set Cache Line Size to 0x10 */
233 // This has no effect but the OS might expect it
234 pci_write_config8(dev, 0x0c, 0x10);
235
Kyösti Mälkkidf128a52019-09-21 18:35:37 +0300236 reg16 = pci_read_config16(dev, PCI_BRIDGE_CONTROL);
237 reg16 &= ~PCI_BRIDGE_CTL_PARITY;
238 reg16 |= PCI_BRIDGE_CTL_NO_ISA;
239 pci_write_config16(dev, PCI_BRIDGE_CONTROL, reg16);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200240
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
Elyes HAOUAS4aec3402018-05-25 08:29:27 +0200270static void pch_pcie_enable(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200271{
272 /* Power Management init before enumeration */
273 pch_pcie_pm_early(dev);
274}
275
Elyes HAOUAS4aec3402018-05-25 08:29:27 +0200276static void pch_pciexp_scan_bridge(struct device *dev)
Marc Jones4adc8cd2012-10-31 16:24:37 -0600277{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100278 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
Marc Jones4adc8cd2012-10-31 16:24:37 -0600279
280 /* Normal PCIe Scan */
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200281 pciexp_scan_bridge(dev);
Marc Jones4adc8cd2012-10-31 16:24:37 -0600282
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100283 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
284 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
285 }
286
Marc Jones4adc8cd2012-10-31 16:24:37 -0600287 /* Late Power Management init after bridge device enumeration */
288 pch_pcie_pm_late(dev);
Marc Jones4adc8cd2012-10-31 16:24:37 -0600289}
290
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600291static const char *pch_pcie_acpi_name(const struct device *dev)
Patrick Rudolph604f6982017-06-07 09:46:52 +0200292{
293 ASSERT(dev);
294
295 if (PCI_SLOT(dev->path.pci.devfn) == 0x1c) {
296 static const char *names[] = { "RP01",
297 "RP02",
298 "RP03",
299 "RP04",
300 "RP05",
301 "RP06",
302 "RP07",
303 "RP08"};
304
305 return names[PCI_FUNC(dev->path.pci.devfn)];
306 }
307
308 return NULL;
309}
310
Stefan Reinauer8e073822012-04-04 00:07:22 +0200311static struct pci_operations pci_ops = {
Subrata Banik15ccbf02019-03-20 15:09:44 +0530312 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200313};
314
315static struct device_operations device_ops = {
316 .read_resources = pci_bus_read_resources,
317 .set_resources = pci_dev_set_resources,
318 .enable_resources = pci_bus_enable_resources,
319 .init = pci_init,
320 .enable = pch_pcie_enable,
Marc Jones4adc8cd2012-10-31 16:24:37 -0600321 .scan_bus = pch_pciexp_scan_bridge,
Patrick Rudolph604f6982017-06-07 09:46:52 +0200322 .acpi_name = pch_pcie_acpi_name,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200323 .ops_pci = &pci_ops,
324};
325
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700326static const unsigned short pci_device_ids[] = { 0x1c10, 0x1c12, 0x1c14, 0x1c16,
327 0x1c18, 0x1c1a, 0x1c1c, 0x1c1e,
328 0x1e10, 0x1e12, 0x1e14, 0x1e16,
329 0x1e18, 0x1e1a, 0x1e1c, 0x1e1e,
330 0 };
Stefan Reinauer8e073822012-04-04 00:07:22 +0200331
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700332static const struct pci_driver pch_pcie __pci_driver = {
333 .ops = &device_ops,
334 .vendor = PCI_VENDOR_ID_INTEL,
335 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200336};