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. static int pcie_portdrv_save_config(struct pci_dev *dev)
  29. {
  30. return pci_save_state(dev);
  31. }
  32. static int pcie_portdrv_restore_config(struct pci_dev *dev)
  33. {
  34. int retval;
  35. pci_restore_state(dev);
  36. retval = pci_enable_device(dev);
  37. if (retval)
  38. return retval;
  39. pci_set_master(dev);
  40. return 0;
  41. }
  42. /*
  43. * pcie_portdrv_probe - Probe PCI-Express port devices
  44. * @dev: PCI-Express port device being probed
  45. *
  46. * If detected invokes the pcie_port_device_register() method for
  47. * this port device.
  48. *
  49. */
  50. static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
  51. const struct pci_device_id *id )
  52. {
  53. int status;
  54. status = pcie_port_device_probe(dev);
  55. if (status)
  56. return status;
  57. if (pci_enable_device(dev) < 0)
  58. return -ENODEV;
  59. pci_set_master(dev);
  60. if (!dev->irq) {
  61. printk(KERN_WARNING
  62. "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n",
  63. __FUNCTION__, dev->device, dev->vendor);
  64. }
  65. if (pcie_port_device_register(dev))
  66. return -ENOMEM;
  67. return 0;
  68. }
  69. static void pcie_portdrv_remove (struct pci_dev *dev)
  70. {
  71. pcie_port_device_remove(dev);
  72. kfree(pci_get_drvdata(dev));
  73. }
  74. #ifdef CONFIG_PM
  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);