portdrv_pci.c 3.0 KB

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