5d339423ff3b81cfbcf5cf2660e8550df75b3314
[coreboot.git] / src / devices / pciexp_device.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2005 Linux Networx
5  * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of 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/pci_ids.h>
25 #include <device/pciexp.h>
26
27 static void pciexp_tune_dev(device_t dev)
28 {
29         unsigned int cap;
30 #if CONFIG_PCIE_TUNING
31         u32 reg32;
32 #endif
33
34         cap = pci_find_capability(dev, PCI_CAP_ID_PCIE);
35         if (!cap)
36                 return;
37
38 #if CONFIG_PCIE_TUNING
39         printk(BIOS_DEBUG, "PCIe: tuning %s\n", dev_path(dev));
40
41         // TODO make this depending on ASPM.
42
43         /* Enable ASPM role based error reporting. */
44         reg32 = pci_read_config32(dev, cap + PCI_EXP_DEVCAP);
45         reg32 |= PCI_EXP_DEVCAP_RBER;
46         pci_write_config32(dev, cap + PCI_EXP_DEVCAP, reg32);
47 #endif
48 }
49
50 unsigned int pciexp_scan_bus(struct bus *bus, unsigned int min_devfn,
51                              unsigned int max_devfn, unsigned int max)
52 {
53         device_t child;
54
55         max = pci_scan_bus(bus, min_devfn, max_devfn, max);
56
57         for (child = bus->children; child; child = child->sibling) {
58                 if ((child->path.pci.devfn < min_devfn) ||
59                     (child->path.pci.devfn > max_devfn)) {
60                         continue;
61                 }
62                 pciexp_tune_dev(child);
63         }
64         return max;
65 }
66
67 unsigned int pciexp_scan_bridge(device_t dev, unsigned int max)
68 {
69         return do_pci_scan_bridge(dev, max, pciexp_scan_bus);
70 }
71
72 /** Default device operations for PCI Express bridges */
73 static struct pci_operations pciexp_bus_ops_pci = {
74         .set_subsystem = 0,
75 };
76
77 struct device_operations default_pciexp_ops_bus = {
78         .read_resources   = pci_bus_read_resources,
79         .set_resources    = pci_dev_set_resources,
80         .enable_resources = pci_bus_enable_resources,
81         .init             = 0,
82         .scan_bus         = pciexp_scan_bridge,
83         .enable           = 0,
84         .reset_bus        = pci_bus_reset,
85         .ops_pci          = &pciexp_bus_ops_pci,
86 };