Angel Pons | 6e5aabd | 2020-03-23 23:44:42 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 2 | |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 3 | #include <device/device.h> |
| 4 | #include <device/pci.h> |
| 5 | #include <device/pciexp.h> |
| 6 | #include <device/pci_ids.h> |
| 7 | #include <assert.h> |
| 8 | |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 9 | static const char *pcie_acpi_name(const struct device *dev) |
| 10 | { |
| 11 | assert(dev); |
| 12 | |
| 13 | if (dev->path.type != DEVICE_PATH_PCI) |
| 14 | return NULL; |
| 15 | |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 16 | assert(dev->upstream); |
| 17 | if (dev->upstream->secondary == 0) |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 18 | switch (dev->path.pci.devfn) { |
| 19 | case PCI_DEVFN(1, 0): |
| 20 | return "PEGP"; |
| 21 | case PCI_DEVFN(1, 1): |
| 22 | return "PEG1"; |
| 23 | case PCI_DEVFN(1, 2): |
| 24 | return "PEG2"; |
| 25 | case PCI_DEVFN(6, 0): |
| 26 | return "PEG6"; |
| 27 | }; |
| 28 | |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 29 | struct device *const port = dev->upstream->dev; |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 30 | assert(port); |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 31 | assert(port->upstream); |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 32 | |
| 33 | if (dev->path.pci.devfn == PCI_DEVFN(0, 0) && |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 34 | port->upstream->secondary == 0 && |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 35 | (port->path.pci.devfn == PCI_DEVFN(1, 0) || |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 36 | port->path.pci.devfn == PCI_DEVFN(1, 1) || |
| 37 | port->path.pci.devfn == PCI_DEVFN(1, 2) || |
| 38 | port->path.pci.devfn == PCI_DEVFN(6, 0))) |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 39 | return "DEV0"; |
| 40 | |
| 41 | return NULL; |
| 42 | } |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 43 | |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 44 | static struct device_operations device_ops = { |
| 45 | .read_resources = pci_bus_read_resources, |
| 46 | .set_resources = pci_dev_set_resources, |
| 47 | .enable_resources = pci_bus_enable_resources, |
| 48 | .scan_bus = pciexp_scan_bridge, |
| 49 | .reset_bus = pci_bus_reset, |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 50 | .init = pci_dev_init, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 51 | .ops_pci = &pci_dev_ops_pci, |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 52 | .acpi_name = pcie_acpi_name, |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 55 | static const unsigned short pci_device_ids[] = { |
| 56 | 0x0101, 0x0105, 0x0109, 0x010d, |
| 57 | 0x0151, 0x0155, 0x0159, 0x015d, |
| 58 | 0, |
| 59 | }; |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 60 | |
| 61 | static const struct pci_driver pch_pcie __pci_driver = { |
| 62 | .ops = &device_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 63 | .vendor = PCI_VID_INTEL, |
Patrick Rudolph | 0b643d2 | 2017-07-05 20:07:06 +0200 | [diff] [blame] | 64 | .devices = pci_device_ids, |
| 65 | }; |