blob: 3f0976868eda656c9a2441caae804c96f9cc3fac [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
17static int pcie_port_bus_match(struct device *dev, struct device_driver *drv);
Pavel Machek7f4927c2005-04-16 15:25:33 -070018static int pcie_port_bus_suspend(struct device *dev, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070019static int pcie_port_bus_resume(struct device *dev);
20
21struct 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};
Zhang, Yanmin48408152006-07-31 15:18:39 +080027EXPORT_SYMBOL_GPL(pcie_port_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29static int pcie_port_bus_match(struct device *dev, struct device_driver *drv)
30{
31 struct pcie_device *pciedev;
32 struct pcie_port_service_driver *driver;
33
34 if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type)
35 return 0;
36
37 pciedev = to_pcie_device(dev);
38 driver = to_service_driver(drv);
39 if ( (driver->id_table->vendor != PCI_ANY_ID &&
40 driver->id_table->vendor != pciedev->id.vendor) ||
41 (driver->id_table->device != PCI_ANY_ID &&
42 driver->id_table->device != pciedev->id.device) ||
Dely Sy8b245e42005-05-06 17:19:09 -070043 (driver->id_table->port_type != PCIE_ANY_PORT &&
44 driver->id_table->port_type != pciedev->id.port_type) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 driver->id_table->service_type != pciedev->id.service_type )
46 return 0;
47
48 return 1;
49}
50
Pavel Machek7f4927c2005-04-16 15:25:33 -070051static int pcie_port_bus_suspend(struct device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
53 struct pcie_device *pciedev;
54 struct pcie_port_service_driver *driver;
55
56 if (!dev || !dev->driver)
57 return 0;
58
59 pciedev = to_pcie_device(dev);
60 driver = to_service_driver(dev->driver);
61 if (driver && driver->suspend)
62 driver->suspend(pciedev, state);
63 return 0;
64}
65
66static int pcie_port_bus_resume(struct device *dev)
67{
68 struct pcie_device *pciedev;
69 struct pcie_port_service_driver *driver;
70
71 if (!dev || !dev->driver)
72 return 0;
73
74 pciedev = to_pcie_device(dev);
75 driver = to_service_driver(dev->driver);
76 if (driver && driver->resume)
77 driver->resume(pciedev);
78 return 0;
79}