isa.rst 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ===========
  2. ISA Drivers
  3. ===========
  4. The following text is adapted from the commit message of the initial
  5. commit of the ISA bus driver authored by Rene Herman.
  6. During the recent "isa drivers using platform devices" discussion it was
  7. pointed out that (ALSA) ISA drivers ran into the problem of not having
  8. the option to fail driver load (device registration rather) upon not
  9. finding their hardware due to a probe() error not being passed up
  10. through the driver model. In the course of that, I suggested a separate
  11. ISA bus might be best; Russell King agreed and suggested this bus could
  12. use the .match() method for the actual device discovery.
  13. The attached does this. For this old non (generically) discoverable ISA
  14. hardware only the driver itself can do discovery so as a difference with
  15. the platform_bus, this isa_bus also distributes match() up to the
  16. driver.
  17. As another difference: these devices only exist in the driver model due
  18. to the driver creating them because it might want to drive them, meaning
  19. that all device creation has been made internal as well.
  20. The usage model this provides is nice, and has been acked from the ALSA
  21. side by Takashi Iwai and Jaroslav Kysela. The ALSA driver module_init's
  22. now (for oldisa-only drivers) become::
  23. static int __init alsa_card_foo_init(void)
  24. {
  25. return isa_register_driver(&snd_foo_isa_driver, SNDRV_CARDS);
  26. }
  27. static void __exit alsa_card_foo_exit(void)
  28. {
  29. isa_unregister_driver(&snd_foo_isa_driver);
  30. }
  31. Quite like the other bus models therefore. This removes a lot of
  32. duplicated init code from the ALSA ISA drivers.
  33. The passed in isa_driver struct is the regular driver struct embedding a
  34. struct device_driver, the normal probe/remove/shutdown/suspend/resume
  35. callbacks, and as indicated that .match callback.
  36. The "SNDRV_CARDS" you see being passed in is a "unsigned int ndev"
  37. parameter, indicating how many devices to create and call our methods
  38. with.
  39. The platform_driver callbacks are called with a platform_device param;
  40. the isa_driver callbacks are being called with a ``struct device *dev,
  41. unsigned int id`` pair directly -- with the device creation completely
  42. internal to the bus it's much cleaner to not leak isa_dev's by passing
  43. them in at all. The id is the only thing we ever want other then the
  44. struct device anyways, and it makes for nicer code in the callbacks as
  45. well.
  46. With this additional .match() callback ISA drivers have all options. If
  47. ALSA would want to keep the old non-load behaviour, it could stick all
  48. of the old .probe in .match, which would only keep them registered after
  49. everything was found to be present and accounted for. If it wanted the
  50. behaviour of always loading as it inadvertently did for a bit after the
  51. changeover to platform devices, it could just not provide a .match() and
  52. do everything in .probe() as before.
  53. If it, as Takashi Iwai already suggested earlier as a way of following
  54. the model from saner buses more closely, wants to load when a later bind
  55. could conceivably succeed, it could use .match() for the prerequisites
  56. (such as checking the user wants the card enabled and that port/irq/dma
  57. values have been passed in) and .probe() for everything else. This is
  58. the nicest model.
  59. To the code...
  60. This exports only two functions; isa_{,un}register_driver().
  61. isa_register_driver() register's the struct device_driver, and then
  62. loops over the passed in ndev creating devices and registering them.
  63. This causes the bus match method to be called for them, which is::
  64. int isa_bus_match(struct device *dev, struct device_driver *driver)
  65. {
  66. struct isa_driver *isa_driver = to_isa_driver(driver);
  67. if (dev->platform_data == isa_driver) {
  68. if (!isa_driver->match ||
  69. isa_driver->match(dev, to_isa_dev(dev)->id))
  70. return 1;
  71. dev->platform_data = NULL;
  72. }
  73. return 0;
  74. }
  75. The first thing this does is check if this device is in fact one of this
  76. driver's devices by seeing if the device's platform_data pointer is set
  77. to this driver. Platform devices compare strings, but we don't need to
  78. do that with everything being internal, so isa_register_driver() abuses
  79. dev->platform_data as a isa_driver pointer which we can then check here.
  80. I believe platform_data is available for this, but if rather not, moving
  81. the isa_driver pointer to the private struct isa_dev is ofcourse fine as
  82. well.
  83. Then, if the the driver did not provide a .match, it matches. If it did,
  84. the driver match() method is called to determine a match.
  85. If it did **not** match, dev->platform_data is reset to indicate this to
  86. isa_register_driver which can then unregister the device again.
  87. If during all this, there's any error, or no devices matched at all
  88. everything is backed out again and the error, or -ENODEV, is returned.
  89. isa_unregister_driver() just unregisters the matched devices and the
  90. driver itself.
  91. module_isa_driver is a helper macro for ISA drivers which do not do
  92. anything special in module init/exit. This eliminates a lot of
  93. boilerplate code. Each module may only use this macro once, and calling
  94. it replaces module_init and module_exit.
  95. max_num_isa_dev is a macro to determine the maximum possible number of
  96. ISA devices which may be registered in the I/O port address space given
  97. the address extent of the ISA devices.