Chris Morgan | 5e5e789 | 2020-02-07 09:40:42 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Chris Morgan | 5e5e789 | 2020-02-07 09:40:42 -0600 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; version 2 of |
| 8 | * the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
| 19 | #include <device/pciexp.h> |
| 20 | #include <device/pci_ids.h> |
| 21 | #include <assert.h> |
| 22 | |
| 23 | static void pcie_disable(struct device *dev) |
| 24 | { |
| 25 | printk(BIOS_INFO, "%s: Disabling device\n", dev_path(dev)); |
| 26 | dev->enabled = 0; |
| 27 | } |
| 28 | |
| 29 | #if CONFIG(HAVE_ACPI_TABLES) |
| 30 | static const char *pcie_acpi_name(const struct device *dev) |
| 31 | { |
| 32 | assert(dev); |
| 33 | |
| 34 | if (dev->path.type != DEVICE_PATH_PCI) |
| 35 | return NULL; |
| 36 | |
| 37 | assert(dev->bus); |
| 38 | if (dev->bus->secondary == 0) |
| 39 | switch (dev->path.pci.devfn) { |
| 40 | case PCI_DEVFN(1, 0): |
| 41 | return "PEGP"; |
| 42 | case PCI_DEVFN(1, 1): |
| 43 | return "PEG1"; |
| 44 | case PCI_DEVFN(1, 2): |
| 45 | return "PEG2"; |
| 46 | }; |
| 47 | |
| 48 | struct device *const port = dev->bus->dev; |
| 49 | assert(port); |
| 50 | assert(port->bus); |
| 51 | |
| 52 | if (dev->path.pci.devfn == PCI_DEVFN(0, 0) && |
| 53 | port->bus->secondary == 0 && |
| 54 | (port->path.pci.devfn == PCI_DEVFN(1, 0) || |
| 55 | port->path.pci.devfn == PCI_DEVFN(1, 1) || |
| 56 | port->path.pci.devfn == PCI_DEVFN(1, 2))) |
| 57 | return "DEV0"; |
| 58 | |
| 59 | return NULL; |
| 60 | } |
| 61 | #endif |
| 62 | |
| 63 | static struct pci_operations pci_ops = { |
| 64 | .set_subsystem = pci_dev_set_subsystem, |
| 65 | }; |
| 66 | |
| 67 | static struct device_operations device_ops = { |
| 68 | .read_resources = pci_bus_read_resources, |
| 69 | .set_resources = pci_dev_set_resources, |
| 70 | .enable_resources = pci_bus_enable_resources, |
| 71 | .scan_bus = pciexp_scan_bridge, |
| 72 | .reset_bus = pci_bus_reset, |
| 73 | .disable = pcie_disable, |
| 74 | .init = pci_dev_init, |
| 75 | .ops_pci = &pci_ops, |
| 76 | #if CONFIG(HAVE_ACPI_TABLES) |
| 77 | .acpi_name = pcie_acpi_name, |
| 78 | #endif |
| 79 | }; |
| 80 | |
| 81 | static const unsigned short pci_device_ids[] = { 0x0c01, 0x0c05, 0x0c09, 0x0c0d, 0 }; |
| 82 | |
| 83 | static const struct pci_driver pch_pcie __pci_driver = { |
| 84 | .ops = &device_ops, |
| 85 | .vendor = PCI_VENDOR_ID_INTEL, |
| 86 | .devices = pci_device_ids, |
| 87 | }; |