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> |
Alex Chiang | 5d9526d | 2008-06-04 11:39:07 -0600 | [diff] [blame] | 16 | #include "portdrv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | 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] | 19 | 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] | 20 | static int pcie_port_bus_resume(struct device *dev); |
| 21 | |
| 22 | struct bus_type pcie_port_bus_type = { |
| 23 | .name = "pci_express", |
| 24 | .match = pcie_port_bus_match, |
| 25 | .suspend = pcie_port_bus_suspend, |
| 26 | .resume = pcie_port_bus_resume, |
| 27 | }; |
Zhang, Yanmin | 4840815 | 2006-07-31 15:18:39 +0800 | [diff] [blame] | 28 | EXPORT_SYMBOL_GPL(pcie_port_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | static int pcie_port_bus_match(struct device *dev, struct device_driver *drv) |
| 31 | { |
| 32 | struct pcie_device *pciedev; |
| 33 | struct pcie_port_service_driver *driver; |
| 34 | |
| 35 | if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type) |
| 36 | return 0; |
| 37 | |
| 38 | pciedev = to_pcie_device(dev); |
| 39 | driver = to_service_driver(drv); |
| 40 | if ( (driver->id_table->vendor != PCI_ANY_ID && |
| 41 | driver->id_table->vendor != pciedev->id.vendor) || |
| 42 | (driver->id_table->device != PCI_ANY_ID && |
| 43 | driver->id_table->device != pciedev->id.device) || |
Dely Sy | 8b245e4 | 2005-05-06 17:19:09 -0700 | [diff] [blame] | 44 | (driver->id_table->port_type != PCIE_ANY_PORT && |
| 45 | driver->id_table->port_type != pciedev->id.port_type) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | driver->id_table->service_type != pciedev->id.service_type ) |
| 47 | return 0; |
| 48 | |
| 49 | return 1; |
| 50 | } |
| 51 | |
Pavel Machek | 7f4927c | 2005-04-16 15:25:33 -0700 | [diff] [blame] | 52 | 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] | 53 | { |
| 54 | struct pcie_device *pciedev; |
| 55 | struct pcie_port_service_driver *driver; |
| 56 | |
| 57 | if (!dev || !dev->driver) |
| 58 | return 0; |
| 59 | |
| 60 | pciedev = to_pcie_device(dev); |
| 61 | driver = to_service_driver(dev->driver); |
| 62 | if (driver && driver->suspend) |
| 63 | driver->suspend(pciedev, state); |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static int pcie_port_bus_resume(struct device *dev) |
| 68 | { |
| 69 | struct pcie_device *pciedev; |
| 70 | struct pcie_port_service_driver *driver; |
| 71 | |
| 72 | if (!dev || !dev->driver) |
| 73 | return 0; |
| 74 | |
| 75 | pciedev = to_pcie_device(dev); |
| 76 | driver = to_service_driver(dev->driver); |
| 77 | if (driver && driver->resume) |
| 78 | driver->resume(pciedev); |
| 79 | return 0; |
| 80 | } |