portdrv_pci.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * File: portdrv_pci.c
  3. * Purpose: PCI Express Port Bus Driver
  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/init.h>
  14. #include <linux/pcieport_if.h>
  15. #include "portdrv.h"
  16. /*
  17. * Version Information
  18. */
  19. #define DRIVER_VERSION "v1.0"
  20. #define DRIVER_AUTHOR "tom.l.nguyen@intel.com"
  21. #define DRIVER_DESC "PCIE Port Bus Driver"
  22. MODULE_AUTHOR(DRIVER_AUTHOR);
  23. MODULE_DESCRIPTION(DRIVER_DESC);
  24. MODULE_LICENSE("GPL");
  25. /* global data */
  26. static const char device_name[] = "pcieport-driver";
  27. /*
  28. * pcie_portdrv_probe - Probe PCI-Express port devices
  29. * @dev: PCI-Express port device being probed
  30. *
  31. * If detected invokes the pcie_port_device_register() method for
  32. * this port device.
  33. *
  34. */
  35. static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
  36. const struct pci_device_id *id )
  37. {
  38. int status;
  39. status = pcie_port_device_probe(dev);
  40. if (status)
  41. return status;
  42. if (pci_enable_device(dev) < 0)
  43. return -ENODEV;
  44. pci_set_master(dev);
  45. if (!dev->irq) {
  46. printk(KERN_WARNING
  47. "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n",
  48. __FUNCTION__, dev->device, dev->vendor);
  49. }
  50. if (pcie_port_device_register(dev))
  51. return -ENOMEM;
  52. return 0;
  53. }
  54. static void pcie_portdrv_remove (struct pci_dev *dev)
  55. {
  56. pcie_port_device_remove(dev);
  57. }
  58. #ifdef CONFIG_PM
  59. static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state)
  60. {
  61. return pcie_port_device_suspend(dev, state);
  62. }
  63. static int pcie_portdrv_resume (struct pci_dev *dev)
  64. {
  65. return pcie_port_device_resume(dev);
  66. }
  67. #endif
  68. /*
  69. * LINUX Device Driver Model
  70. */
  71. static const struct pci_device_id port_pci_ids[] = { {
  72. /* handle any PCI-Express port */
  73. PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
  74. }, { /* end: all zeroes */ }
  75. };
  76. MODULE_DEVICE_TABLE(pci, port_pci_ids);
  77. static struct pci_driver pcie_portdrv = {
  78. .name = (char *)device_name,
  79. .id_table = &port_pci_ids[0],
  80. .probe = pcie_portdrv_probe,
  81. .remove = pcie_portdrv_remove,
  82. #ifdef CONFIG_PM
  83. .suspend = pcie_portdrv_suspend,
  84. .resume = pcie_portdrv_resume,
  85. #endif /* PM */
  86. };
  87. static int __init pcie_portdrv_init(void)
  88. {
  89. int retval = 0;
  90. pcie_port_bus_register();
  91. retval = pci_register_driver(&pcie_portdrv);
  92. if (retval)
  93. pcie_port_bus_unregister();
  94. return retval;
  95. }
  96. static void __exit pcie_portdrv_exit(void)
  97. {
  98. pci_unregister_driver(&pcie_portdrv);
  99. pcie_port_bus_unregister();
  100. }
  101. module_init(pcie_portdrv_init);
  102. module_exit(pcie_portdrv_exit);