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