blob: 9cb823e34cf73bd63a18d3a53a55b71848b36f64 [file] [log] [blame]
Patrick Rudolph0b643d22017-07-05 20:07:06 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2017-2018 Patrick Rudolph <siro@das-labor.org>
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
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>
22#include <assert.h>
23
24static void pcie_disable(struct device *dev)
25{
26 printk(BIOS_INFO, "%s: Disabling device\n", dev_path(dev));
27 dev->enabled = 0;
28}
29
30#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
31static const char *pcie_acpi_name(const struct device *dev)
32{
33 assert(dev);
34
35 if (dev->path.type != DEVICE_PATH_PCI)
36 return NULL;
37
38 assert(dev->bus);
39 if (dev->bus->secondary == 0)
40 switch (dev->path.pci.devfn) {
41 case PCI_DEVFN(1, 0):
42 return "PEGP";
43 case PCI_DEVFN(1, 1):
44 return "PEG1";
45 case PCI_DEVFN(1, 2):
46 return "PEG2";
47 case PCI_DEVFN(6, 0):
48 return "PEG6";
49 };
50
51 const device_t port = dev->bus->dev;
52 assert(port);
53 assert(port->bus);
54
55 if (dev->path.pci.devfn == PCI_DEVFN(0, 0) &&
56 port->bus->secondary == 0 &&
57 (port->path.pci.devfn == PCI_DEVFN(1, 0) ||
58 port->path.pci.devfn == PCI_DEVFN(1, 1) ||
59 port->path.pci.devfn == PCI_DEVFN(1, 2) ||
60 port->path.pci.devfn == PCI_DEVFN(6, 0)))
61 return "DEV0";
62
63 return NULL;
64}
65#endif
66
67static void
68pcie_set_subsystem(struct device *dev, unsigned int ven, unsigned int device)
69{
70 /* NOTE: This is not the default position! */
71 if (!ven || !device)
72 pci_write_config32(dev, 0x94,
73 pci_read_config32(dev, 0));
74 else
75 pci_write_config32(dev, 0x94,
76 ((device & 0xffff) << 16) | (ven & 0xffff));
77}
78
79static struct pci_operations pci_ops = {
80 .set_subsystem = pcie_set_subsystem,
81};
82
83static struct device_operations device_ops = {
84 .read_resources = pci_bus_read_resources,
85 .set_resources = pci_dev_set_resources,
86 .enable_resources = pci_bus_enable_resources,
87 .scan_bus = pciexp_scan_bridge,
88 .reset_bus = pci_bus_reset,
89 .disable = pcie_disable,
90 .init = pci_dev_init,
91 .ops_pci = &pci_ops,
92#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
93 .acpi_name = pcie_acpi_name,
94#endif
95};
96
97static const unsigned short pci_device_ids[] = { 0x0101, 0x0105, 0x0109, 0x010d,
98 0x0151, 0x0155, 0x0159, 0x015d,
99 0 };
100
101static const struct pci_driver pch_pcie __pci_driver = {
102 .ops = &device_ops,
103 .vendor = PCI_VENDOR_ID_INTEL,
104 .devices = pci_device_ids,
105};