ide-scan-pci.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * support for probing IDE PCI devices in the PCI bus order
  3. *
  4. * Copyright (c) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  5. * Copyright (c) 1995-1998 Mark Lord
  6. *
  7. * May be copied or modified under the terms of the GNU General Public License
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/ide.h>
  13. /*
  14. * Module interfaces
  15. */
  16. static int pre_init = 1; /* Before first ordered IDE scan */
  17. static LIST_HEAD(ide_pci_drivers);
  18. /*
  19. * __ide_pci_register_driver - attach IDE driver
  20. * @driver: pci driver
  21. * @module: owner module of the driver
  22. *
  23. * Registers a driver with the IDE layer. The IDE layer arranges that
  24. * boot time setup is done in the expected device order and then
  25. * hands the controllers off to the core PCI code to do the rest of
  26. * the work.
  27. *
  28. * Returns are the same as for pci_register_driver
  29. */
  30. int __ide_pci_register_driver(struct pci_driver *driver, struct module *module,
  31. const char *mod_name)
  32. {
  33. if (!pre_init)
  34. return __pci_register_driver(driver, module, mod_name);
  35. driver->driver.owner = module;
  36. list_add_tail(&driver->node, &ide_pci_drivers);
  37. return 0;
  38. }
  39. EXPORT_SYMBOL_GPL(__ide_pci_register_driver);
  40. /**
  41. * ide_scan_pcidev - find an IDE driver for a device
  42. * @dev: PCI device to check
  43. *
  44. * Look for an IDE driver to handle the device we are considering.
  45. * This is only used during boot up to get the ordering correct. After
  46. * boot up the pci layer takes over the job.
  47. */
  48. static int __init ide_scan_pcidev(struct pci_dev *dev)
  49. {
  50. struct list_head *l;
  51. struct pci_driver *d;
  52. list_for_each(l, &ide_pci_drivers) {
  53. d = list_entry(l, struct pci_driver, node);
  54. if (d->id_table) {
  55. const struct pci_device_id *id =
  56. pci_match_id(d->id_table, dev);
  57. if (id != NULL && d->probe(dev, id) >= 0) {
  58. dev->driver = d;
  59. pci_dev_get(dev);
  60. return 1;
  61. }
  62. }
  63. }
  64. return 0;
  65. }
  66. /**
  67. * ide_scan_pcibus - perform the initial IDE driver scan
  68. *
  69. * Perform the initial bus rather than driver ordered scan of the
  70. * PCI drivers. After this all IDE pci handling becomes standard
  71. * module ordering not traditionally ordered.
  72. */
  73. static int __init ide_scan_pcibus(void)
  74. {
  75. struct pci_dev *dev = NULL;
  76. struct pci_driver *d;
  77. struct list_head *l, *n;
  78. pre_init = 0;
  79. for_each_pci_dev(dev)
  80. ide_scan_pcidev(dev);
  81. /*
  82. * Hand the drivers over to the PCI layer now we
  83. * are post init.
  84. */
  85. list_for_each_safe(l, n, &ide_pci_drivers) {
  86. list_del(l);
  87. d = list_entry(l, struct pci_driver, node);
  88. if (__pci_register_driver(d, d->driver.owner,
  89. d->driver.mod_name))
  90. printk(KERN_ERR "%s: failed to register %s driver\n",
  91. __func__, d->driver.mod_name);
  92. }
  93. return 0;
  94. }
  95. module_init(ide_scan_pcibus);