blob: 5ab18f649072a59d0cede50fd480a6335dbd7591 [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
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
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>
26#include "pch.h"
27
Stefan Reinauer8e073822012-04-04 00:07:22 +020028static void pch_pcie_pm_early(struct device *dev)
29{
30 u16 link_width_p0, link_width_p4;
31 u8 slot_power_limit = 10; /* 10W for x1 */
32 u32 reg32;
33 u8 reg8;
34
Duncan Laurie4aca5d72012-04-27 10:58:22 -070035 reg32 = RCBA32(RPC);
36
37 /* Port 0-3 link aggregation from PCIEPCS1[1:0] soft strap */
38 switch (reg32 & 3) {
39 case 3:
40 link_width_p0 = 4;
41 break;
42 case 1:
43 case 2:
44 link_width_p0 = 2;
45 break;
46 case 0:
47 default:
48 link_width_p0 = 1;
49 }
50
51 /* Port 4-7 link aggregation from PCIEPCS2[1:0] soft strap */
52 switch ((reg32 >> 2) & 3) {
53 case 3:
54 link_width_p4 = 4;
55 break;
56 case 1:
57 case 2:
58 link_width_p4 = 2;
59 break;
60 case 0:
61 default:
62 link_width_p4 = 1;
63 }
Stefan Reinauer8e073822012-04-04 00:07:22 +020064
65 /* Enable dynamic clock gating where needed */
66 reg8 = pci_read_config8(dev, 0xe1);
67 switch (PCI_FUNC(dev->path.pci.devfn)) {
68 case 0: /* Port 0 */
69 if (link_width_p0 == 4)
70 slot_power_limit = 40; /* 40W for x4 */
71 else if (link_width_p0 == 2)
72 slot_power_limit = 20; /* 20W for x2 */
Duncan Laurie4aca5d72012-04-27 10:58:22 -070073 reg8 |= 0x3f;
74 break;
Stefan Reinauer8e073822012-04-04 00:07:22 +020075 case 4: /* Port 4 */
76 if (link_width_p4 == 4)
77 slot_power_limit = 40; /* 40W for x4 */
78 else if (link_width_p4 == 2)
79 slot_power_limit = 20; /* 20W for x2 */
80 reg8 |= 0x3f;
81 break;
82 case 1: /* Port 1 only if Port 0 is x1 */
83 if (link_width_p0 == 1)
84 reg8 |= 0x3;
85 break;
86 case 2: /* Port 2 only if Port 0 is x1 or x2 */
87 case 3: /* Port 3 only if Port 0 is x1 or x2 */
88 if (link_width_p0 <= 2)
89 reg8 |= 0x3;
90 break;
91 case 5: /* Port 5 only if Port 4 is x1 */
92 if (link_width_p4 == 1)
93 reg8 |= 0x3;
94 break;
95 case 6: /* Port 7 only if Port 4 is x1 or x2 */
96 case 7: /* Port 7 only if Port 4 is x1 or x2 */
97 if (link_width_p4 <= 2)
98 reg8 |= 0x3;
99 break;
100 }
101 pci_write_config8(dev, 0xe1, reg8);
102
103 /* Set 0xE8[0] = 1 */
104 reg32 = pci_read_config32(dev, 0xe8);
105 reg32 |= 1;
106 pci_write_config32(dev, 0xe8, reg32);
107
108 /* Adjust Common Clock exit latency */
109 reg32 = pci_read_config32(dev, 0xd8);
110 reg32 &= ~(1 << 17);
111 reg32 |= (1 << 16) | (1 << 15);
112 reg32 &= ~(1 << 31); /* Disable PME# SCI for native PME handling */
113 pci_write_config32(dev, 0xd8, reg32);
114
115 /* Adjust ASPM L1 exit latency */
116 reg32 = pci_read_config32(dev, 0x4c);
117 reg32 &= ~((1 << 17) | (1 << 16) | (1 << 15));
118 if (RCBA32(0x2320) & (1 << 16)) {
119 /* If RCBA+2320[15]=1 set ASPM L1 to 8-16us */
120 reg32 |= (1 << 17);
121 } else {
122 /* Else set ASPM L1 to 2-4us */
123 reg32 |= (1 << 16);
124 }
125 pci_write_config32(dev, 0x4c, reg32);
126
127 /* Set slot power limit as configured above */
128 reg32 = pci_read_config32(dev, 0x54);
129 reg32 &= ~((1 << 15) | (1 << 16)); /* 16:15 = Slot power scale */
130 reg32 &= ~(0xff << 7); /* 14:7 = Slot power limit */
131 reg32 |= (slot_power_limit << 7);
132 pci_write_config32(dev, 0x54, reg32);
133}
134
135static void pch_pcie_pm_late(struct device *dev)
136{
137 enum aspm_type apmc;
138 u32 reg32;
139
140 /* Set 0x314 = 0x743a361b */
141 pci_mmio_write_config32(dev, 0x314, 0x743a361b);
142
143 /* Set 0x318[31:16] = 0x1414 */
144 reg32 = pci_mmio_read_config32(dev, 0x318);
145 reg32 &= 0x0000ffff;
146 reg32 |= 0x14140000;
147 pci_mmio_write_config32(dev, 0x318, reg32);
148
149 /* Set 0x324[5] = 1 */
150 reg32 = pci_mmio_read_config32(dev, 0x324);
151 reg32 |= (1 << 5);
152 pci_mmio_write_config32(dev, 0x324, reg32);
153
154 /* Set 0x330[7:0] = 0x40 */
155 reg32 = pci_mmio_read_config32(dev, 0x330);
156 reg32 &= ~(0xff);
157 reg32 |= 0x40;
158 pci_mmio_write_config32(dev, 0x330, reg32);
159
160 /* Set 0x33C[24:0] = 0x854c74 */
161 reg32 = pci_mmio_read_config32(dev, 0x33c);
162 reg32 &= 0xff000000;
163 reg32 |= 0x00854c74;
164 pci_mmio_write_config32(dev, 0x33c, reg32);
165
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
171 /* Get configured ASPM state */
172 apmc = pci_read_config32(dev, 0x50) & 3;
173
174 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
175 if (apmc == PCIE_ASPM_BOTH) {
176 reg32 = pci_read_config32(dev, 0xe8);
177 reg32 |= (1 << 1);
178 pci_write_config32(dev, 0xe8, reg32);
179 }
180}
181
182static void pci_init(struct device *dev)
183{
184 u16 reg16;
185 u32 reg32;
186
187 printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n");
188
189 /* Enable Bus Master */
190 reg32 = pci_read_config32(dev, PCI_COMMAND);
191 reg32 |= PCI_COMMAND_MASTER;
192 pci_write_config32(dev, PCI_COMMAND, reg32);
193
194 /* Set Cache Line Size to 0x10 */
195 // This has no effect but the OS might expect it
196 pci_write_config8(dev, 0x0c, 0x10);
197
198 reg16 = pci_read_config16(dev, 0x3e);
199 reg16 &= ~(1 << 0); /* disable parity error response */
200 // reg16 &= ~(1 << 1); /* disable SERR */
201 reg16 |= (1 << 2); /* ISA enable */
202 pci_write_config16(dev, 0x3e, reg16);
203
204#ifdef EVEN_MORE_DEBUG
205 reg32 = pci_read_config32(dev, 0x20);
206 printk(BIOS_SPEW, " MBL = 0x%08x\n", reg32);
207 reg32 = pci_read_config32(dev, 0x24);
208 printk(BIOS_SPEW, " PMBL = 0x%08x\n", reg32);
209 reg32 = pci_read_config32(dev, 0x28);
210 printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", reg32);
211 reg32 = pci_read_config32(dev, 0x2c);
212 printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", reg32);
213#endif
214
215 /* Clear errors in status registers */
216 reg16 = pci_read_config16(dev, 0x06);
217 //reg16 |= 0xf900;
218 pci_write_config16(dev, 0x06, reg16);
219
220 reg16 = pci_read_config16(dev, 0x1e);
221 //reg16 |= 0xf900;
222 pci_write_config16(dev, 0x1e, reg16);
223
224 /* Power Management init after enumeration */
225 pch_pcie_pm_late(dev);
226}
227
228static void pch_pcie_enable(device_t dev)
229{
230 /* Power Management init before enumeration */
231 pch_pcie_pm_early(dev);
232}
233
234static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device)
235{
236 /* NOTE: This is not the default position! */
237 if (!vendor || !device) {
238 pci_write_config32(dev, 0x94,
239 pci_read_config32(dev, 0));
240 } else {
241 pci_write_config32(dev, 0x94,
242 ((device & 0xffff) << 16) | (vendor & 0xffff));
243 }
244}
245
246static struct pci_operations pci_ops = {
247 .set_subsystem = pcie_set_subsystem,
248};
249
250static struct device_operations device_ops = {
251 .read_resources = pci_bus_read_resources,
252 .set_resources = pci_dev_set_resources,
253 .enable_resources = pci_bus_enable_resources,
254 .init = pci_init,
255 .enable = pch_pcie_enable,
256 .scan_bus = pciexp_scan_bridge,
257 .ops_pci = &pci_ops,
258};
259
260static const struct pci_driver pch_pcie_port1 __pci_driver = {
261 .ops = &device_ops,
262 .vendor = PCI_VENDOR_ID_INTEL,
263 .device = 0x1c10, /* D28:F0 */
264};
265
266static const struct pci_driver pch_pcie_port1_a __pci_driver = {
267 .ops = &device_ops,
268 .vendor = PCI_VENDOR_ID_INTEL,
269 .device = 0x1e10, /* D28:F0 */
270};
271
272static const struct pci_driver pch_pcie_port2 __pci_driver = {
273 .ops = &device_ops,
274 .vendor = PCI_VENDOR_ID_INTEL,
275 .device = 0x1c12, /* D28:F1 */
276};
277
278static const struct pci_driver pch_pcie_port3 __pci_driver = {
279 .ops = &device_ops,
280 .vendor = PCI_VENDOR_ID_INTEL,
281 .device = 0x1c14, /* D28:F2 */
282};
283
284static const struct pci_driver pch_pcie_port3_a __pci_driver = {
285 .ops = &device_ops,
286 .vendor = PCI_VENDOR_ID_INTEL,
287 .device = 0x1e14, /* D28:F2 */
288};
289
290static const struct pci_driver pch_pcie_port4 __pci_driver = {
291 .ops = &device_ops,
292 .vendor = PCI_VENDOR_ID_INTEL,
293 .device = 0x1c16, /* D28:F3 */
294};
295
296static const struct pci_driver pch_pcie_port4_a __pci_driver = {
297 .ops = &device_ops,
298 .vendor = PCI_VENDOR_ID_INTEL,
299 .device = 0x1e16, /* D28:F3 */
300};
301
302static const struct pci_driver pch_pcie_port5 __pci_driver = {
303 .ops = &device_ops,
304 .vendor = PCI_VENDOR_ID_INTEL,
305 .device = 0x1c18, /* D28:F4 */
306};
307
308static const struct pci_driver pch_pcie_port6 __pci_driver = {
309 .ops = &device_ops,
310 .vendor = PCI_VENDOR_ID_INTEL,
311 .device = 0x1c1a, /* D28:F5 */
312};
313
314static const struct pci_driver pch_pcie_port7 __pci_driver = {
315 .ops = &device_ops,
316 .vendor = PCI_VENDOR_ID_INTEL,
317 .device = 0x1c1c, /* D28:F6 */
318};
319
320static const struct pci_driver pch_pcie_port8 __pci_driver = {
321 .ops = &device_ops,
322 .vendor = PCI_VENDOR_ID_INTEL,
323 .device = 0x1c1e, /* D28:F7 */
324};