blob: 458729d0db841bf64a38cf2c0cfcc1171494a769 [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>
Arthur Heymansd2d2aef2018-01-16 14:19:37 +010024#include <southbridge/intel/common/rcba.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020025#include "pch.h"
26
Stefan Reinauer8e073822012-04-04 00:07:22 +020027static void pch_pcie_pm_early(struct device *dev)
28{
29 u16 link_width_p0, link_width_p4;
30 u8 slot_power_limit = 10; /* 10W for x1 */
31 u32 reg32;
32 u8 reg8;
33
Duncan Laurie4aca5d72012-04-27 10:58:22 -070034 reg32 = RCBA32(RPC);
35
36 /* Port 0-3 link aggregation from PCIEPCS1[1:0] soft strap */
37 switch (reg32 & 3) {
38 case 3:
39 link_width_p0 = 4;
40 break;
41 case 1:
42 case 2:
43 link_width_p0 = 2;
44 break;
45 case 0:
46 default:
47 link_width_p0 = 1;
48 }
49
50 /* Port 4-7 link aggregation from PCIEPCS2[1:0] soft strap */
51 switch ((reg32 >> 2) & 3) {
52 case 3:
53 link_width_p4 = 4;
54 break;
55 case 1:
56 case 2:
57 link_width_p4 = 2;
58 break;
59 case 0:
60 default:
61 link_width_p4 = 1;
62 }
Stefan Reinauer8e073822012-04-04 00:07:22 +020063
64 /* Enable dynamic clock gating where needed */
65 reg8 = pci_read_config8(dev, 0xe1);
66 switch (PCI_FUNC(dev->path.pci.devfn)) {
67 case 0: /* Port 0 */
68 if (link_width_p0 == 4)
69 slot_power_limit = 40; /* 40W for x4 */
70 else if (link_width_p0 == 2)
71 slot_power_limit = 20; /* 20W for x2 */
Duncan Laurie4aca5d72012-04-27 10:58:22 -070072 reg8 |= 0x3f;
73 break;
Stefan Reinauer8e073822012-04-04 00:07:22 +020074 case 4: /* Port 4 */
75 if (link_width_p4 == 4)
76 slot_power_limit = 40; /* 40W for x4 */
77 else if (link_width_p4 == 2)
78 slot_power_limit = 20; /* 20W for x2 */
79 reg8 |= 0x3f;
80 break;
81 case 1: /* Port 1 only if Port 0 is x1 */
82 if (link_width_p0 == 1)
83 reg8 |= 0x3;
84 break;
85 case 2: /* Port 2 only if Port 0 is x1 or x2 */
86 case 3: /* Port 3 only if Port 0 is x1 or x2 */
87 if (link_width_p0 <= 2)
88 reg8 |= 0x3;
89 break;
90 case 5: /* Port 5 only if Port 4 is x1 */
91 if (link_width_p4 == 1)
92 reg8 |= 0x3;
93 break;
94 case 6: /* Port 7 only if Port 4 is x1 or x2 */
95 case 7: /* Port 7 only if Port 4 is x1 or x2 */
96 if (link_width_p4 <= 2)
97 reg8 |= 0x3;
98 break;
99 }
100 pci_write_config8(dev, 0xe1, reg8);
101
102 /* Set 0xE8[0] = 1 */
103 reg32 = pci_read_config32(dev, 0xe8);
104 reg32 |= 1;
105 pci_write_config32(dev, 0xe8, reg32);
106
107 /* Adjust Common Clock exit latency */
108 reg32 = pci_read_config32(dev, 0xd8);
109 reg32 &= ~(1 << 17);
110 reg32 |= (1 << 16) | (1 << 15);
111 reg32 &= ~(1 << 31); /* Disable PME# SCI for native PME handling */
112 pci_write_config32(dev, 0xd8, reg32);
113
114 /* Adjust ASPM L1 exit latency */
115 reg32 = pci_read_config32(dev, 0x4c);
116 reg32 &= ~((1 << 17) | (1 << 16) | (1 << 15));
117 if (RCBA32(0x2320) & (1 << 16)) {
118 /* If RCBA+2320[15]=1 set ASPM L1 to 8-16us */
119 reg32 |= (1 << 17);
120 } else {
121 /* Else set ASPM L1 to 2-4us */
122 reg32 |= (1 << 16);
123 }
124 pci_write_config32(dev, 0x4c, reg32);
125
126 /* Set slot power limit as configured above */
127 reg32 = pci_read_config32(dev, 0x54);
128 reg32 &= ~((1 << 15) | (1 << 16)); /* 16:15 = Slot power scale */
129 reg32 &= ~(0xff << 7); /* 14:7 = Slot power limit */
130 reg32 |= (slot_power_limit << 7);
131 pci_write_config32(dev, 0x54, reg32);
132}
133
134static void pch_pcie_pm_late(struct device *dev)
135{
Marc Jones4adc8cd2012-10-31 16:24:37 -0600136 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
137 enum aspm_type apmc = 0;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200138 u32 reg32;
139
140 /* Set 0x314 = 0x743a361b */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300141 pci_write_config32(dev, 0x314, 0x743a361b);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200142
143 /* Set 0x318[31:16] = 0x1414 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300144 reg32 = pci_read_config32(dev, 0x318);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200145 reg32 &= 0x0000ffff;
146 reg32 |= 0x14140000;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300147 pci_write_config32(dev, 0x318, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200148
149 /* Set 0x324[5] = 1 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300150 reg32 = pci_read_config32(dev, 0x324);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200151 reg32 |= (1 << 5);
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300152 pci_write_config32(dev, 0x324, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200153
154 /* Set 0x330[7:0] = 0x40 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300155 reg32 = pci_read_config32(dev, 0x330);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200156 reg32 &= ~(0xff);
157 reg32 |= 0x40;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300158 pci_write_config32(dev, 0x330, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200159
160 /* Set 0x33C[24:0] = 0x854c74 */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300161 reg32 = pci_read_config32(dev, 0x33c);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200162 reg32 &= 0xff000000;
163 reg32 |= 0x00854c74;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300164 pci_write_config32(dev, 0x33c, reg32);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200165
166 /* No IO-APIC, Disable EOI forwarding */
167 reg32 = pci_read_config32(dev, 0xd4);
168 reg32 |= (1 << 1);
169 pci_write_config32(dev, 0xd4, reg32);
170
Marc Jones4adc8cd2012-10-31 16:24:37 -0600171 /* Check for a rootport ASPM override */
172 switch (PCI_FUNC(dev->path.pci.devfn)) {
173 case 0:
174 apmc = config->pcie_aspm_f0;
175 break;
176 case 1:
177 apmc = config->pcie_aspm_f1;
178 break;
179 case 2:
180 apmc = config->pcie_aspm_f2;
181 break;
182 case 3:
183 apmc = config->pcie_aspm_f3;
184 break;
185 case 4:
186 apmc = config->pcie_aspm_f4;
187 break;
188 case 5:
189 apmc = config->pcie_aspm_f5;
190 break;
191 case 6:
192 apmc = config->pcie_aspm_f6;
193 break;
194 case 7:
195 apmc = config->pcie_aspm_f7;
196 break;
197 }
198
199 /* Setup the override or get the real ASPM setting */
200 if (apmc) {
201 reg32 = pci_read_config32(dev, 0xd4);
202 reg32 |= (apmc << 2) | (1 << 4);
203 pci_write_config32(dev, 0xd4, reg32);
204 } else {
205 apmc = pci_read_config32(dev, 0x50) & 3;
206 }
Stefan Reinauer8e073822012-04-04 00:07:22 +0200207
208 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
209 if (apmc == PCIE_ASPM_BOTH) {
210 reg32 = pci_read_config32(dev, 0xe8);
211 reg32 |= (1 << 1);
212 pci_write_config32(dev, 0xe8, reg32);
213 }
214}
215
216static void pci_init(struct device *dev)
217{
218 u16 reg16;
219 u32 reg32;
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100220 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200221
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);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100258
259 /* Enable expresscard hotplug events. */
260 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
261 pci_write_config32(dev, 0xd8,
262 pci_read_config32(dev, 0xd8)
263 | (1 << 30));
264 pci_write_config16(dev, 0x42, 0x142);
265 }
Stefan Reinauer8e073822012-04-04 00:07:22 +0200266}
267
Elyes HAOUAS4aec3402018-05-25 08:29:27 +0200268static void pch_pcie_enable(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200269{
270 /* Power Management init before enumeration */
271 pch_pcie_pm_early(dev);
272}
273
Elyes HAOUAS4aec3402018-05-25 08:29:27 +0200274static void pch_pciexp_scan_bridge(struct device *dev)
Marc Jones4adc8cd2012-10-31 16:24:37 -0600275{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100276 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
Marc Jones4adc8cd2012-10-31 16:24:37 -0600277
278 /* Normal PCIe Scan */
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200279 pciexp_scan_bridge(dev);
Marc Jones4adc8cd2012-10-31 16:24:37 -0600280
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100281 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
282 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
283 }
284
Marc Jones4adc8cd2012-10-31 16:24:37 -0600285 /* Late Power Management init after bridge device enumeration */
286 pch_pcie_pm_late(dev);
Marc Jones4adc8cd2012-10-31 16:24:37 -0600287}
288
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600289static const char *pch_pcie_acpi_name(const struct device *dev)
Patrick Rudolph604f6982017-06-07 09:46:52 +0200290{
291 ASSERT(dev);
292
293 if (PCI_SLOT(dev->path.pci.devfn) == 0x1c) {
294 static const char *names[] = { "RP01",
295 "RP02",
296 "RP03",
297 "RP04",
298 "RP05",
299 "RP06",
300 "RP07",
301 "RP08"};
302
303 return names[PCI_FUNC(dev->path.pci.devfn)];
304 }
305
306 return NULL;
307}
308
Elyes HAOUAS4aec3402018-05-25 08:29:27 +0200309static void pcie_set_subsystem(struct device *dev, unsigned vendor,
310 unsigned device)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200311{
312 /* NOTE: This is not the default position! */
313 if (!vendor || !device) {
314 pci_write_config32(dev, 0x94,
315 pci_read_config32(dev, 0));
316 } else {
317 pci_write_config32(dev, 0x94,
318 ((device & 0xffff) << 16) | (vendor & 0xffff));
319 }
320}
321
322static struct pci_operations pci_ops = {
323 .set_subsystem = pcie_set_subsystem,
324};
325
326static struct device_operations device_ops = {
327 .read_resources = pci_bus_read_resources,
328 .set_resources = pci_dev_set_resources,
329 .enable_resources = pci_bus_enable_resources,
330 .init = pci_init,
331 .enable = pch_pcie_enable,
Marc Jones4adc8cd2012-10-31 16:24:37 -0600332 .scan_bus = pch_pciexp_scan_bridge,
Patrick Rudolph604f6982017-06-07 09:46:52 +0200333 .acpi_name = pch_pcie_acpi_name,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200334 .ops_pci = &pci_ops,
335};
336
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700337static const unsigned short pci_device_ids[] = { 0x1c10, 0x1c12, 0x1c14, 0x1c16,
338 0x1c18, 0x1c1a, 0x1c1c, 0x1c1e,
339 0x1e10, 0x1e12, 0x1e14, 0x1e16,
340 0x1e18, 0x1e1a, 0x1e1c, 0x1e1e,
341 0 };
Stefan Reinauer8e073822012-04-04 00:07:22 +0200342
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700343static const struct pci_driver pch_pcie __pci_driver = {
344 .ops = &device_ops,
345 .vendor = PCI_VENDOR_ID_INTEL,
346 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200347};