blob: 80cd3550e1fb26edb14746d74c872ec3a8c3677b [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
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
28static void pch_pcie_pm_early(struct device *dev)
29{
30/* RPC has been moved. It is in PCI config space now. */
31#if 0
32 u16 link_width_p0, link_width_p4;
33 u8 slot_power_limit = 10; /* 10W for x1 */
34 u32 reg32;
35 u8 reg8;
36
37 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 }
66
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 */
75 reg8 |= 0x3f;
76 break;
77 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));
120 if (RCBA32(0x2320) & (1 << 16)) {
121 /* 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#endif
136}
137
138static void pch_pcie_pm_late(struct device *dev)
139{
140 enum aspm_type apmc;
141 u32 reg32;
142
143 /* Set 0x314 = 0x743a361b */
144 pci_mmio_write_config32(dev, 0x314, 0x743a361b);
145
146 /* Set 0x318[31:16] = 0x1414 */
147 reg32 = pci_mmio_read_config32(dev, 0x318);
148 reg32 &= 0x0000ffff;
149 reg32 |= 0x14140000;
150 pci_mmio_write_config32(dev, 0x318, reg32);
151
152 /* Set 0x324[5] = 1 */
153 reg32 = pci_mmio_read_config32(dev, 0x324);
154 reg32 |= (1 << 5);
155 pci_mmio_write_config32(dev, 0x324, reg32);
156
157 /* Set 0x330[7:0] = 0x40 */
158 reg32 = pci_mmio_read_config32(dev, 0x330);
159 reg32 &= ~(0xff);
160 reg32 |= 0x40;
161 pci_mmio_write_config32(dev, 0x330, reg32);
162
163 /* Set 0x33C[24:0] = 0x854c74 */
164 reg32 = pci_mmio_read_config32(dev, 0x33c);
165 reg32 &= 0xff000000;
166 reg32 |= 0x00854c74;
167 pci_mmio_write_config32(dev, 0x33c, reg32);
168
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
174 /* Get configured ASPM state */
175 apmc = pci_read_config32(dev, 0x50) & 3;
176
177 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
178 if (apmc == PCIE_ASPM_BOTH) {
179 reg32 = pci_read_config32(dev, 0xe8);
180 reg32 |= (1 << 1);
181 pci_write_config32(dev, 0xe8, reg32);
182 }
183}
184
185static void pci_init(struct device *dev)
186{
187 u16 reg16;
188 u32 reg32;
189
190 printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n");
191
192 /* Enable Bus Master */
193 reg32 = pci_read_config32(dev, PCI_COMMAND);
194 reg32 |= PCI_COMMAND_MASTER;
195 pci_write_config32(dev, PCI_COMMAND, reg32);
196
197 /* Set Cache Line Size to 0x10 */
198 // This has no effect but the OS might expect it
199 pci_write_config8(dev, 0x0c, 0x10);
200
201 reg16 = pci_read_config16(dev, 0x3e);
202 reg16 &= ~(1 << 0); /* disable parity error response */
203 // reg16 &= ~(1 << 1); /* disable SERR */
204 reg16 |= (1 << 2); /* ISA enable */
205 pci_write_config16(dev, 0x3e, reg16);
206
207#ifdef EVEN_MORE_DEBUG
208 reg32 = pci_read_config32(dev, 0x20);
209 printk(BIOS_SPEW, " MBL = 0x%08x\n", reg32);
210 reg32 = pci_read_config32(dev, 0x24);
211 printk(BIOS_SPEW, " PMBL = 0x%08x\n", reg32);
212 reg32 = pci_read_config32(dev, 0x28);
213 printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", reg32);
214 reg32 = pci_read_config32(dev, 0x2c);
215 printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", reg32);
216#endif
217
218 /* Clear errors in status registers */
219 reg16 = pci_read_config16(dev, 0x06);
220 //reg16 |= 0xf900;
221 pci_write_config16(dev, 0x06, reg16);
222
223 reg16 = pci_read_config16(dev, 0x1e);
224 //reg16 |= 0xf900;
225 pci_write_config16(dev, 0x1e, reg16);
226
227 /* Power Management init after enumeration */
228 pch_pcie_pm_late(dev);
229}
230
231static void pch_pcie_enable(device_t dev)
232{
233 /* Power Management init before enumeration */
234 pch_pcie_pm_early(dev);
235}
236
237static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device)
238{
239 /* NOTE: This is not the default position! */
240 if (!vendor || !device) {
241 pci_write_config32(dev, 0x94,
242 pci_read_config32(dev, 0));
243 } else {
244 pci_write_config32(dev, 0x94,
245 ((device & 0xffff) << 16) | (vendor & 0xffff));
246 }
247}
248
249static struct pci_operations pci_ops = {
250 .set_subsystem = pcie_set_subsystem,
251};
252
253static struct device_operations device_ops = {
254 .read_resources = pci_bus_read_resources,
255 .set_resources = pci_dev_set_resources,
256 .enable_resources = pci_bus_enable_resources,
257 .init = pci_init,
258 .enable = pch_pcie_enable,
259 .scan_bus = pciexp_scan_bridge,
260 .ops_pci = &pci_ops,
261};
262
263static const unsigned short pci_device_ids[] = { 0x1c10, 0x1c12, 0x1c14, 0x1c16,
264 0x1c18, 0x1c1a, 0x1c1c, 0x1c1e,
265 0x1e10, 0x1e12, 0x1e14, 0x1e16,
266 0x1e18, 0x1e1a, 0x1e1c, 0x1e1e,
267 0 };
268
269static const struct pci_driver pch_pcie __pci_driver = {
270 .ops = &device_ops,
271 .vendor = PCI_VENDOR_ID_INTEL,
272 .devices = pci_device_ids,
273};