drm_module.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* SPDX-License-Identifier: MIT */
  2. #ifndef DRM_MODULE_H
  3. #define DRM_MODULE_H
  4. #include <linux/pci.h>
  5. #include <linux/platform_device.h>
  6. #include <drm/drm_drv.h>
  7. /**
  8. * DOC: overview
  9. *
  10. * This library provides helpers registering DRM drivers during module
  11. * initialization and shutdown. The provided helpers act like bus-specific
  12. * module helpers, such as module_pci_driver(), but respect additional
  13. * parameters that control DRM driver registration.
  14. *
  15. * Below is an example of initializing a DRM driver for a device on the
  16. * PCI bus.
  17. *
  18. * .. code-block:: c
  19. *
  20. * struct pci_driver my_pci_drv = {
  21. * };
  22. *
  23. * drm_module_pci_driver(my_pci_drv);
  24. *
  25. * The generated code will test if DRM drivers are enabled and register
  26. * the PCI driver my_pci_drv. For more complex module initialization, you
  27. * can still use module_init() and module_exit() in your driver.
  28. */
  29. /*
  30. * PCI drivers
  31. */
  32. static inline int __init drm_pci_register_driver(struct pci_driver *pci_drv)
  33. {
  34. if (drm_firmware_drivers_only())
  35. return -ENODEV;
  36. return pci_register_driver(pci_drv);
  37. }
  38. /**
  39. * drm_module_pci_driver - Register a DRM driver for PCI-based devices
  40. * @__pci_drv: the PCI driver structure
  41. *
  42. * Registers a DRM driver for devices on the PCI bus. The helper
  43. * macro behaves like module_pci_driver() but tests the state of
  44. * drm_firmware_drivers_only(). For more complex module initialization,
  45. * use module_init() and module_exit() directly.
  46. *
  47. * Each module may only use this macro once. Calling it replaces
  48. * module_init() and module_exit().
  49. */
  50. #define drm_module_pci_driver(__pci_drv) \
  51. module_driver(__pci_drv, drm_pci_register_driver, pci_unregister_driver)
  52. static inline int __init
  53. drm_pci_register_driver_if_modeset(struct pci_driver *pci_drv, int modeset)
  54. {
  55. if (drm_firmware_drivers_only() && modeset == -1)
  56. return -ENODEV;
  57. if (modeset == 0)
  58. return -ENODEV;
  59. return pci_register_driver(pci_drv);
  60. }
  61. static inline void __exit
  62. drm_pci_unregister_driver_if_modeset(struct pci_driver *pci_drv, int modeset)
  63. {
  64. pci_unregister_driver(pci_drv);
  65. }
  66. /**
  67. * drm_module_pci_driver_if_modeset - Register a DRM driver for PCI-based devices
  68. * @__pci_drv: the PCI driver structure
  69. * @__modeset: an additional parameter that disables the driver
  70. *
  71. * This macro is deprecated and only provided for existing drivers. For
  72. * new drivers, use drm_module_pci_driver().
  73. *
  74. * Registers a DRM driver for devices on the PCI bus. The helper macro
  75. * behaves like drm_module_pci_driver() with an additional driver-specific
  76. * flag. If __modeset is 0, the driver has been disabled, if __modeset is
  77. * -1 the driver state depends on the global DRM state. For all other
  78. * values, the PCI driver has been enabled. The default should be -1.
  79. */
  80. #define drm_module_pci_driver_if_modeset(__pci_drv, __modeset) \
  81. module_driver(__pci_drv, drm_pci_register_driver_if_modeset, \
  82. drm_pci_unregister_driver_if_modeset, __modeset)
  83. /*
  84. * Platform drivers
  85. */
  86. static inline int __init
  87. drm_platform_driver_register(struct platform_driver *platform_drv)
  88. {
  89. if (drm_firmware_drivers_only())
  90. return -ENODEV;
  91. return platform_driver_register(platform_drv);
  92. }
  93. /**
  94. * drm_module_platform_driver - Register a DRM driver for platform devices
  95. * @__platform_drv: the platform driver structure
  96. *
  97. * Registers a DRM driver for devices on the platform bus. The helper
  98. * macro behaves like module_platform_driver() but tests the state of
  99. * drm_firmware_drivers_only(). For more complex module initialization,
  100. * use module_init() and module_exit() directly.
  101. *
  102. * Each module may only use this macro once. Calling it replaces
  103. * module_init() and module_exit().
  104. */
  105. #define drm_module_platform_driver(__platform_drv) \
  106. module_driver(__platform_drv, drm_platform_driver_register, \
  107. platform_driver_unregister)
  108. #endif