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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | struct bus_type pcie_port_bus_type = { |
| 21 | .name = "pci_express", |
| 22 | .match = pcie_port_bus_match, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | }; |
Zhang, Yanmin | 4840815 | 2006-07-31 15:18:39 +0800 | [diff] [blame] | 24 | EXPORT_SYMBOL_GPL(pcie_port_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | static int pcie_port_bus_match(struct device *dev, struct device_driver *drv) |
| 27 | { |
| 28 | struct pcie_device *pciedev; |
| 29 | struct pcie_port_service_driver *driver; |
| 30 | |
| 31 | if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type) |
| 32 | return 0; |
Rafael J. Wysocki | 2210636 | 2009-01-13 14:46:46 +0100 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | pciedev = to_pcie_device(dev); |
| 35 | driver = to_service_driver(drv); |
Rafael J. Wysocki | 2210636 | 2009-01-13 14:46:46 +0100 | [diff] [blame] | 36 | |
| 37 | if (driver->service != pciedev->service) |
| 38 | return 0; |
| 39 | |
Kenji Kaneshige | 694f88e | 2009-11-25 21:06:15 +0900 | [diff] [blame] | 40 | if ((driver->port_type != PCIE_ANY_PORT) && |
| 41 | (driver->port_type != pciedev->port->pcie_type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | return 0; |
| 43 | |
| 44 | return 1; |
| 45 | } |
Rafael J. Wysocki | fa6c993 | 2009-01-01 19:52:12 +0100 | [diff] [blame] | 46 | |
| 47 | int pcie_port_bus_register(void) |
| 48 | { |
| 49 | return bus_register(&pcie_port_bus_type); |
| 50 | } |
| 51 | |
| 52 | void pcie_port_bus_unregister(void) |
| 53 | { |
| 54 | bus_unregister(&pcie_port_bus_type); |
| 55 | } |