blob: 51fdd2e76d9264f3fbc6db11addd469460df0254 [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
Duncan Laurieb9fe01c2012-04-27 10:30:51 -07005 * Copyright (C) 2012 The Chromium OS Authors. All rights reserved.
Stefan Reinauer8e073822012-04-04 00:07:22 +02006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Stefan Reinauer8e073822012-04-04 00:07:22 +020016 */
17
18#include <console/console.h>
19#include <delay.h>
Marc Jones783f2262013-02-11 14:36:35 -070020#ifdef __SMM__
21#include <arch/io.h>
Marc Jones783f2262013-02-11 14:36:35 -070022#include <device/pci_def.h>
23#else /* !__SMM__ */
Stefan Reinauer8e073822012-04-04 00:07:22 +020024#include <device/device.h>
25#include <device/pci.h>
Marc Jones783f2262013-02-11 14:36:35 -070026#endif
Stefan Reinauer8e073822012-04-04 00:07:22 +020027#include "pch.h"
28
Stefan Reinauer8e073822012-04-04 00:07:22 +020029
30int pch_silicon_revision(void)
31{
Felix Held82bd0c32016-08-13 23:27:15 +020032 static int pch_revision_id = -1;
Marc Jones783f2262013-02-11 14:36:35 -070033
Antonello Dettoridac82402016-09-02 09:14:39 +020034#ifdef __SIMPLE_DEVICE__
35 pci_devfn_t dev;
Marc Jones783f2262013-02-11 14:36:35 -070036 dev = PCI_DEV(0, 0x1f, 0);
37#else
Antonello Dettoridac82402016-09-02 09:14:39 +020038 device_t dev;
Marc Jones783f2262013-02-11 14:36:35 -070039 dev = dev_find_slot(0, PCI_DEVFN(0x1f, 0));
40#endif
41
Stefan Reinauer8e073822012-04-04 00:07:22 +020042 if (pch_revision_id < 0)
Marc Jones783f2262013-02-11 14:36:35 -070043 pch_revision_id = pci_read_config8(dev, PCI_REVISION_ID);
Stefan Reinauer8e073822012-04-04 00:07:22 +020044 return pch_revision_id;
45}
46
Duncan Laurieb9fe01c2012-04-27 10:30:51 -070047int pch_silicon_type(void)
48{
Felix Held82bd0c32016-08-13 23:27:15 +020049 static int pch_type = -1;
Marc Jones783f2262013-02-11 14:36:35 -070050
Antonello Dettoridac82402016-09-02 09:14:39 +020051#ifdef __SIMPLE_DEVICE__
52 pci_devfn_t dev;
Marc Jones783f2262013-02-11 14:36:35 -070053 dev = PCI_DEV(0, 0x1f, 0);
54#else
Antonello Dettoridac82402016-09-02 09:14:39 +020055 device_t dev;
Marc Jones783f2262013-02-11 14:36:35 -070056 dev = dev_find_slot(0, PCI_DEVFN(0x1f, 0));
57#endif
58
Duncan Laurieb9fe01c2012-04-27 10:30:51 -070059 if (pch_type < 0)
Marc Jones783f2262013-02-11 14:36:35 -070060 pch_type = pci_read_config8(dev, PCI_DEVICE_ID + 1);
Duncan Laurieb9fe01c2012-04-27 10:30:51 -070061 return pch_type;
62}
63
64int pch_silicon_supported(int type, int rev)
65{
66 int cur_type = pch_silicon_type();
67 int cur_rev = pch_silicon_revision();
68
69 switch (type) {
70 case PCH_TYPE_CPT:
71 /* CougarPoint minimum revision */
72 if (cur_type == PCH_TYPE_CPT && cur_rev >= rev)
73 return 1;
74 /* PantherPoint any revision */
75 if (cur_type == PCH_TYPE_PPT)
76 return 1;
77 break;
78
79 case PCH_TYPE_PPT:
80 /* PantherPoint minimum revision */
81 if (cur_type == PCH_TYPE_PPT && cur_rev >= rev)
82 return 1;
83 break;
84 }
85
86 return 0;
87}
88
Stefan Reinauer8e073822012-04-04 00:07:22 +020089#define IOBP_RETRY 1000
90static inline int iobp_poll(void)
91{
92 unsigned try = IOBP_RETRY;
93 u32 data;
94
95 while (try--) {
96 data = RCBA32(IOBPS);
97 if ((data & 1) == 0)
98 return 1;
99 udelay(10);
100 }
101
102 printk(BIOS_ERR, "IOBP timeout\n");
103 return 0;
104}
105
106void pch_iobp_update(u32 address, u32 andvalue, u32 orvalue)
107{
108 u32 data;
109
110 /* Set the address */
111 RCBA32(IOBPIRI) = address;
112
113 /* READ OPCODE */
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700114 if (pch_silicon_supported(PCH_TYPE_CPT, PCH_STEP_B0))
Stefan Reinauer8e073822012-04-04 00:07:22 +0200115 RCBA32(IOBPS) = IOBPS_RW_BX;
116 else
117 RCBA32(IOBPS) = IOBPS_READ_AX;
118 if (!iobp_poll())
119 return;
120
121 /* Read IOBP data */
122 data = RCBA32(IOBPD);
123 if (!iobp_poll())
124 return;
125
126 /* Check for successful transaction */
127 if ((RCBA32(IOBPS) & 0x6) != 0) {
128 printk(BIOS_ERR, "IOBP read 0x%08x failed\n", address);
129 return;
130 }
131
132 /* Update the data */
133 data &= andvalue;
134 data |= orvalue;
135
136 /* WRITE OPCODE */
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700137 if (pch_silicon_supported(PCH_TYPE_CPT, PCH_STEP_B0))
Stefan Reinauer8e073822012-04-04 00:07:22 +0200138 RCBA32(IOBPS) = IOBPS_RW_BX;
139 else
140 RCBA32(IOBPS) = IOBPS_WRITE_AX;
141 if (!iobp_poll())
142 return;
143
144 /* Write IOBP data */
145 RCBA32(IOBPD) = data;
146 if (!iobp_poll())
147 return;
148}
149
Marc Jones783f2262013-02-11 14:36:35 -0700150#ifndef __SMM__
151/* Set bit in Function Disble register to hide this device */
152static void pch_hide_devfn(unsigned devfn)
153{
154 switch (devfn) {
155 case PCI_DEVFN(22, 0): /* MEI #1 */
156 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
157 break;
158 case PCI_DEVFN(22, 1): /* MEI #2 */
159 RCBA32_OR(FD2, PCH_DISABLE_MEI2);
160 break;
161 case PCI_DEVFN(22, 2): /* IDE-R */
162 RCBA32_OR(FD2, PCH_DISABLE_IDER);
163 break;
164 case PCI_DEVFN(22, 3): /* KT */
165 RCBA32_OR(FD2, PCH_DISABLE_KT);
166 break;
167 case PCI_DEVFN(25, 0): /* Gigabit Ethernet */
168 RCBA32_OR(BUC, PCH_DISABLE_GBE);
169 break;
170 case PCI_DEVFN(26, 0): /* EHCI #2 */
171 RCBA32_OR(FD, PCH_DISABLE_EHCI2);
172 break;
173 case PCI_DEVFN(27, 0): /* HD Audio Controller */
174 RCBA32_OR(FD, PCH_DISABLE_HD_AUDIO);
175 break;
176 case PCI_DEVFN(28, 0): /* PCI Express Root Port 1 */
177 case PCI_DEVFN(28, 1): /* PCI Express Root Port 2 */
178 case PCI_DEVFN(28, 2): /* PCI Express Root Port 3 */
179 case PCI_DEVFN(28, 3): /* PCI Express Root Port 4 */
180 case PCI_DEVFN(28, 4): /* PCI Express Root Port 5 */
181 case PCI_DEVFN(28, 5): /* PCI Express Root Port 6 */
182 case PCI_DEVFN(28, 6): /* PCI Express Root Port 7 */
183 case PCI_DEVFN(28, 7): /* PCI Express Root Port 8 */
184 RCBA32_OR(FD, PCH_DISABLE_PCIE(PCI_FUNC(devfn)));
185 break;
186 case PCI_DEVFN(29, 0): /* EHCI #1 */
187 RCBA32_OR(FD, PCH_DISABLE_EHCI1);
188 break;
189 case PCI_DEVFN(30, 0): /* PCI-to-PCI Bridge */
190 RCBA32_OR(FD, PCH_DISABLE_P2P);
191 break;
192 case PCI_DEVFN(31, 0): /* LPC */
193 RCBA32_OR(FD, PCH_DISABLE_LPC);
194 break;
195 case PCI_DEVFN(31, 2): /* SATA #1 */
196 RCBA32_OR(FD, PCH_DISABLE_SATA1);
197 break;
198 case PCI_DEVFN(31, 3): /* SMBUS */
199 RCBA32_OR(FD, PCH_DISABLE_SMBUS);
200 break;
201 case PCI_DEVFN(31, 5): /* SATA #22 */
202 RCBA32_OR(FD, PCH_DISABLE_SATA2);
203 break;
204 case PCI_DEVFN(31, 6): /* Thermal Subsystem */
205 RCBA32_OR(FD, PCH_DISABLE_THERMAL);
206 break;
207 }
208}
209
Stefan Reinauer8e073822012-04-04 00:07:22 +0200210/* Check if any port in set X to X+3 is enabled */
211static int pch_pcie_check_set_enabled(device_t dev)
212{
213 device_t port;
214 int port_func;
215 int dev_func = PCI_FUNC(dev->path.pci.devfn);
216
217 printk(BIOS_DEBUG, "%s: check set enabled\n", dev_path(dev));
218
219 /* Go through static device tree list of devices
220 * because enumeration is still in progress */
221 for (port = all_devices; port; port = port->next) {
222 /* Only care about PCIe root ports */
223 if (PCI_SLOT(port->path.pci.devfn) !=
224 PCI_SLOT(dev->path.pci.devfn))
225 continue;
226
227 /* Check if port is in range and enabled */
228 port_func = PCI_FUNC(port->path.pci.devfn);
229 if (port_func >= dev_func &&
230 port_func < (dev_func + 4) &&
231 port->enabled)
232 return 1;
233 }
234
235 /* None of the ports in this set are enabled */
236 return 0;
237}
238
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700239/* RPFN is a write-once register so keep a copy until it is written */
240static u32 new_rpfn;
241
242/* Swap function numbers assigned to two PCIe Root Ports */
243static void pch_pcie_function_swap(u8 old_fn, u8 new_fn)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200244{
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700245 u32 old_rpfn = new_rpfn;
246
247 printk(BIOS_DEBUG, "PCH: Remap PCIe function %d to %d\n",
248 old_fn, new_fn);
249
250 new_rpfn &= ~(RPFN_FNMASK(old_fn) | RPFN_FNMASK(new_fn));
251
252 /* Old function set to new function and disabled */
253 new_rpfn |= RPFN_FNSET(old_fn, RPFN_FNGET(old_rpfn, new_fn));
254 new_rpfn |= RPFN_FNSET(new_fn, RPFN_FNGET(old_rpfn, old_fn));
255}
256
257/* Update devicetree with new Root Port function number assignment */
258static void pch_pcie_devicetree_update(void)
259{
260 device_t dev;
261
262 /* Update the function numbers in the static devicetree */
263 for (dev = all_devices; dev; dev = dev->next) {
264 u8 new_devfn;
265
266 /* Only care about PCH PCIe root ports */
267 if (PCI_SLOT(dev->path.pci.devfn) !=
268 PCH_PCIE_DEV_SLOT)
269 continue;
270
271 /* Determine the new devfn for this port */
272 new_devfn = PCI_DEVFN(PCH_PCIE_DEV_SLOT,
273 RPFN_FNGET(new_rpfn,
274 PCI_FUNC(dev->path.pci.devfn)));
275
276 if (dev->path.pci.devfn != new_devfn) {
277 printk(BIOS_DEBUG,
278 "PCH: PCIe map %02x.%1x -> %02x.%1x\n",
279 PCI_SLOT(dev->path.pci.devfn),
280 PCI_FUNC(dev->path.pci.devfn),
281 PCI_SLOT(new_devfn), PCI_FUNC(new_devfn));
282
283 dev->path.pci.devfn = new_devfn;
284 }
285 }
286}
287
288/* Special handling for PCIe Root Port devices */
289static void pch_pcie_enable(device_t dev)
290{
291 struct southbridge_intel_bd82x6x_config *config = dev->chip_info;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200292 u32 reg32;
293
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700294 /*
295 * Save a copy of the Root Port Function Number map when
296 * starting to walk the list of PCIe Root Ports so it can
297 * be updated locally and written out when the last port
298 * has been processed.
299 */
300 if (PCI_FUNC(dev->path.pci.devfn) == 0) {
301 new_rpfn = RCBA32(RPFN);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200302
303 /*
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700304 * Enable Root Port coalescing if the first port is disabled
305 * or the other devices will not be enumerated by the OS.
306 */
307 if (!dev->enabled)
308 config->pcie_port_coalesce = 1;
309
310 if (config->pcie_port_coalesce)
311 printk(BIOS_INFO,
312 "PCH: PCIe Root Port coalescing is enabled\n");
313 }
314
315 if (!dev->enabled) {
Marc Jonesef6b08c2012-06-15 23:03:15 -0600316 printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev));
317
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700318 /*
319 * PCIE Power Savings for PantherPoint and CougarPoint/B1+
Stefan Reinauer8e073822012-04-04 00:07:22 +0200320 *
321 * If PCIe 0-3 disabled set Function 0 0xE2[0] = 1
322 * If PCIe 4-7 disabled set Function 4 0xE2[0] = 1
323 *
324 * This check is done here instead of pcie driver
325 * because the pcie driver enable() handler is not
326 * called unless the device is enabled.
327 */
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700328 if ((PCI_FUNC(dev->path.pci.devfn) == 0 ||
Stefan Reinauer8e073822012-04-04 00:07:22 +0200329 PCI_FUNC(dev->path.pci.devfn) == 4)) {
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700330 /* Handle workaround for PPT and CPT/B1+ */
331 if (pch_silicon_supported(PCH_TYPE_CPT, PCH_STEP_B1) &&
332 !pch_pcie_check_set_enabled(dev)) {
Stefan Reinauer8e073822012-04-04 00:07:22 +0200333 u8 reg8 = pci_read_config8(dev, 0xe2);
334 reg8 |= 1;
335 pci_write_config8(dev, 0xe2, reg8);
336 }
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700337
338 /*
339 * Enable Clock Gating for shared PCIe resources
340 * before disabling this particular port.
341 */
342 pci_write_config8(dev, 0xe1, 0x3c);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200343 }
344
345 /* Ensure memory, io, and bus master are all disabled */
346 reg32 = pci_read_config32(dev, PCI_COMMAND);
347 reg32 &= ~(PCI_COMMAND_MASTER |
Duncan Laurieb9fe01c2012-04-27 10:30:51 -0700348 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
349 pci_write_config32(dev, PCI_COMMAND, reg32);
350
351 /* Do not claim downstream transactions for PCIe ports */
352 new_rpfn |= RPFN_HIDE(PCI_FUNC(dev->path.pci.devfn));
353
354 /* Hide this device if possible */
355 pch_hide_devfn(dev->path.pci.devfn);
356 } else {
357 int fn;
358
359 /*
360 * Check if there is a lower disabled port to swap with this
361 * port in order to maintain linear order starting at zero.
362 */
363 if (config->pcie_port_coalesce) {
364 for (fn=0; fn < PCI_FUNC(dev->path.pci.devfn); fn++) {
365 if (!(new_rpfn & RPFN_HIDE(fn)))
366 continue;
367
368 /* Swap places with this function */
369 pch_pcie_function_swap(
370 PCI_FUNC(dev->path.pci.devfn), fn);
371 break;
372 }
373 }
374
375 /* Enable SERR */
376 reg32 = pci_read_config32(dev, PCI_COMMAND);
377 reg32 |= PCI_COMMAND_SERR;
378 pci_write_config32(dev, PCI_COMMAND, reg32);
379 }
380
381 /*
382 * When processing the last PCIe root port we can now
383 * update the Root Port Function Number and Hide register.
384 */
385 if (PCI_FUNC(dev->path.pci.devfn) == 7) {
386 printk(BIOS_SPEW, "PCH: RPFN 0x%08x -> 0x%08x\n",
387 RCBA32(RPFN), new_rpfn);
388 RCBA32(RPFN) = new_rpfn;
389
390 /* Update static devictree with new function numbers */
391 if (config->pcie_port_coalesce)
392 pch_pcie_devicetree_update();
393 }
394}
395
396void pch_enable(device_t dev)
397{
398 u32 reg32;
399
400 /* PCH PCIe Root Ports get special handling */
401 if (PCI_SLOT(dev->path.pci.devfn) == PCH_PCIE_DEV_SLOT)
402 return pch_pcie_enable(dev);
403
404 if (!dev->enabled) {
405 printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev));
406
407 /* Ensure memory, io, and bus master are all disabled */
408 reg32 = pci_read_config32(dev, PCI_COMMAND);
409 reg32 &= ~(PCI_COMMAND_MASTER |
410 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200411 pci_write_config32(dev, PCI_COMMAND, reg32);
412
413 /* Hide this device if possible */
414 pch_hide_devfn(dev->path.pci.devfn);
415 } else {
416 /* Enable SERR */
417 reg32 = pci_read_config32(dev, PCI_COMMAND);
418 reg32 |= PCI_COMMAND_SERR;
419 pci_write_config32(dev, PCI_COMMAND, reg32);
420 }
421}
422
423struct chip_operations southbridge_intel_bd82x6x_ops = {
Stefan Reinauer9ca1c0a2012-07-25 16:10:36 -0700424 CHIP_NAME("Intel Series 6/7 (Cougar Point/Panther Point) Southbridge")
Stefan Reinauer8e073822012-04-04 00:07:22 +0200425 .enable_dev = pch_enable,
426};
Marc Jones783f2262013-02-11 14:36:35 -0700427#endif