blob: 686930d80addee0dec56347e21c26cb8dd653876 [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älkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020021#include <device/pciexp.h>
22#include <device/pci_ids.h>
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010023#include <southbridge/intel/common/pciehp.h>
Patrick Rudolph604f6982017-06-07 09:46:52 +020024#include <assert.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030025
26#include "chip.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));
Patrick Rudolph4f8b1082019-07-14 11:54:58 +0200119 if (RCBA32(CIR9) & (1 << 16)) {
Stefan Reinauer8e073822012-04-04 00:07:22 +0200120 /* 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
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};