portdrv_bus.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include <linux/module.h>
  9. #include <linux/pci.h>
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/pm.h>
  13. #include <linux/pcieport_if.h>
  14. #include "portdrv.h"
  15. static int pcie_port_bus_match(struct device *dev, struct device_driver *drv);
  16. struct bus_type pcie_port_bus_type = {
  17. .name = "pci_express",
  18. .match = pcie_port_bus_match,
  19. };
  20. EXPORT_SYMBOL_GPL(pcie_port_bus_type);
  21. static int pcie_port_bus_match(struct device *dev, struct device_driver *drv)
  22. {
  23. struct pcie_device *pciedev;
  24. struct pcie_port_data *port_data;
  25. struct pcie_port_service_driver *driver;
  26. if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type)
  27. return 0;
  28. pciedev = to_pcie_device(dev);
  29. driver = to_service_driver(drv);
  30. if (driver->service != pciedev->service)
  31. return 0;
  32. port_data = pci_get_drvdata(pciedev->port);
  33. if (driver->port_type != PCIE_ANY_PORT
  34. && driver->port_type != port_data->port_type)
  35. return 0;
  36. return 1;
  37. }
  38. int pcie_port_bus_register(void)
  39. {
  40. return bus_register(&pcie_port_bus_type);
  41. }
  42. void pcie_port_bus_unregister(void)
  43. {
  44. bus_unregister(&pcie_port_bus_type);
  45. }