Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File: portdrv_bus.c |
| 3 | * Purpose: PCI Express Port Bus Driver's Bus Overloading Functions |
| 4 | * |
| 5 | * Copyright (C) 2004 Intel |
| 6 | * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com) |
| 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/pci.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/pm.h> |
| 14 | |
| 15 | #include <linux/pcieport_if.h> |
| 16 | |
| 17 | static int pcie_port_bus_match(struct device *dev, struct device_driver *drv); |
Pavel Machek | 7f4927c | 2005-04-16 15:25:33 -0700 | [diff] [blame^] | 18 | static int pcie_port_bus_suspend(struct device *dev, pm_message_t state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | static int pcie_port_bus_resume(struct device *dev); |
| 20 | |
| 21 | struct bus_type pcie_port_bus_type = { |
| 22 | .name = "pci_express", |
| 23 | .match = pcie_port_bus_match, |
| 24 | .suspend = pcie_port_bus_suspend, |
| 25 | .resume = pcie_port_bus_resume, |
| 26 | }; |
| 27 | |
| 28 | static int pcie_port_bus_match(struct device *dev, struct device_driver *drv) |
| 29 | { |
| 30 | struct pcie_device *pciedev; |
| 31 | struct pcie_port_service_driver *driver; |
| 32 | |
| 33 | if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type) |
| 34 | return 0; |
| 35 | |
| 36 | pciedev = to_pcie_device(dev); |
| 37 | driver = to_service_driver(drv); |
| 38 | if ( (driver->id_table->vendor != PCI_ANY_ID && |
| 39 | driver->id_table->vendor != pciedev->id.vendor) || |
| 40 | (driver->id_table->device != PCI_ANY_ID && |
| 41 | driver->id_table->device != pciedev->id.device) || |
| 42 | driver->id_table->port_type != pciedev->id.port_type || |
| 43 | driver->id_table->service_type != pciedev->id.service_type ) |
| 44 | return 0; |
| 45 | |
| 46 | return 1; |
| 47 | } |
| 48 | |
Pavel Machek | 7f4927c | 2005-04-16 15:25:33 -0700 | [diff] [blame^] | 49 | static int pcie_port_bus_suspend(struct device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
| 51 | struct pcie_device *pciedev; |
| 52 | struct pcie_port_service_driver *driver; |
| 53 | |
| 54 | if (!dev || !dev->driver) |
| 55 | return 0; |
| 56 | |
| 57 | pciedev = to_pcie_device(dev); |
| 58 | driver = to_service_driver(dev->driver); |
| 59 | if (driver && driver->suspend) |
| 60 | driver->suspend(pciedev, state); |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int pcie_port_bus_resume(struct device *dev) |
| 65 | { |
| 66 | struct pcie_device *pciedev; |
| 67 | struct pcie_port_service_driver *driver; |
| 68 | |
| 69 | if (!dev || !dev->driver) |
| 70 | return 0; |
| 71 | |
| 72 | pciedev = to_pcie_device(dev); |
| 73 | driver = to_service_driver(dev->driver); |
| 74 | if (driver && driver->resume) |
| 75 | driver->resume(pciedev); |
| 76 | return 0; |
| 77 | } |