portdrv_pci.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. return -ENOMEM;
  53. return 0;
  54. }
  55. static void pcie_portdrv_remove (struct pci_dev *dev)
  56. {
  57. pcie_port_device_remove(dev);
  58. kfree(pci_get_drvdata(dev));
  59. }
  60. #ifdef CONFIG_PM
  61. static int pcie_portdrv_save_config(struct pci_dev *dev)
  62. {
  63. return pci_save_state(dev);
  64. }
  65. static int pcie_portdrv_restore_config(struct pci_dev *dev)
  66. {
  67. int retval;
  68. pci_restore_state(dev);
  69. retval = pci_enable_device(dev);
  70. if (retval)
  71. return retval;
  72. pci_set_master(dev);
  73. return 0;
  74. }
  75. static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state)
  76. {
  77. int ret = pcie_port_device_suspend(dev, state);
  78. if (!ret)
  79. ret = pcie_portdrv_save_config(dev);
  80. return ret;
  81. }
  82. static int pcie_portdrv_resume (struct pci_dev *dev)
  83. {
  84. pcie_portdrv_restore_config(dev);
  85. return pcie_port_device_resume(dev);
  86. }
  87. #endif
  88. /*
  89. * LINUX Device Driver Model
  90. */
  91. static const struct pci_device_id port_pci_ids[] = { {
  92. /* handle any PCI-Express port */
  93. PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
  94. }, { /* end: all zeroes */ }
  95. };
  96. MODULE_DEVICE_TABLE(pci, port_pci_ids);
  97. static struct pci_driver pcie_portdrv = {
  98. .name = (char *)device_name,
  99. .id_table = &port_pci_ids[0],
  100. .probe = pcie_portdrv_probe,
  101. .remove = pcie_portdrv_remove,
  102. #ifdef CONFIG_PM
  103. .suspend = pcie_portdrv_suspend,
  104. .resume = pcie_portdrv_resume,
  105. #endif /* PM */
  106. };
  107. static int __init pcie_portdrv_init(void)
  108. {
  109. int retval = 0;
  110. pcie_port_bus_register();
  111. retval = pci_register_driver(&pcie_portdrv);
  112. if (retval)
  113. pcie_port_bus_unregister();
  114. return retval;
  115. }
  116. static void __exit pcie_portdrv_exit(void)
  117. {
  118. pci_unregister_driver(&pcie_portdrv);
  119. pcie_port_bus_unregister();
  120. }
  121. module_init(pcie_portdrv_init);
  122. module_exit(pcie_portdrv_exit);