126 lines · c
1/* SPDX-License-Identifier: MIT */2 3#ifndef DRM_MODULE_H4#define DRM_MODULE_H5 6#include <linux/pci.h>7#include <linux/platform_device.h>8 9#include <drm/drm_drv.h>10 11/**12 * DOC: overview13 *14 * This library provides helpers registering DRM drivers during module15 * initialization and shutdown. The provided helpers act like bus-specific16 * module helpers, such as module_pci_driver(), but respect additional17 * parameters that control DRM driver registration.18 *19 * Below is an example of initializing a DRM driver for a device on the20 * PCI bus.21 *22 * .. code-block:: c23 *24 * struct pci_driver my_pci_drv = {25 * };26 *27 * drm_module_pci_driver(my_pci_drv);28 *29 * The generated code will test if DRM drivers are enabled and register30 * the PCI driver my_pci_drv. For more complex module initialization, you31 * can still use module_init() and module_exit() in your driver.32 */33 34/*35 * PCI drivers36 */37 38static inline int __init drm_pci_register_driver(struct pci_driver *pci_drv)39{40 if (drm_firmware_drivers_only())41 return -ENODEV;42 43 return pci_register_driver(pci_drv);44}45 46/**47 * drm_module_pci_driver - Register a DRM driver for PCI-based devices48 * @__pci_drv: the PCI driver structure49 *50 * Registers a DRM driver for devices on the PCI bus. The helper51 * macro behaves like module_pci_driver() but tests the state of52 * drm_firmware_drivers_only(). For more complex module initialization,53 * use module_init() and module_exit() directly.54 *55 * Each module may only use this macro once. Calling it replaces56 * module_init() and module_exit().57 */58#define drm_module_pci_driver(__pci_drv) \59 module_driver(__pci_drv, drm_pci_register_driver, pci_unregister_driver)60 61static inline int __init62drm_pci_register_driver_if_modeset(struct pci_driver *pci_drv, int modeset)63{64 if (drm_firmware_drivers_only() && modeset == -1)65 return -ENODEV;66 if (modeset == 0)67 return -ENODEV;68 69 return pci_register_driver(pci_drv);70}71 72static inline void __exit73drm_pci_unregister_driver_if_modeset(struct pci_driver *pci_drv, int modeset)74{75 pci_unregister_driver(pci_drv);76}77 78/**79 * drm_module_pci_driver_if_modeset - Register a DRM driver for PCI-based devices80 * @__pci_drv: the PCI driver structure81 * @__modeset: an additional parameter that disables the driver82 *83 * This macro is deprecated and only provided for existing drivers. For84 * new drivers, use drm_module_pci_driver().85 *86 * Registers a DRM driver for devices on the PCI bus. The helper macro87 * behaves like drm_module_pci_driver() with an additional driver-specific88 * flag. If __modeset is 0, the driver has been disabled, if __modeset is89 * -1 the driver state depends on the global DRM state. For all other90 * values, the PCI driver has been enabled. The default should be -1.91 */92#define drm_module_pci_driver_if_modeset(__pci_drv, __modeset) \93 module_driver(__pci_drv, drm_pci_register_driver_if_modeset, \94 drm_pci_unregister_driver_if_modeset, __modeset)95 96/*97 * Platform drivers98 */99 100static inline int __init101drm_platform_driver_register(struct platform_driver *platform_drv)102{103 if (drm_firmware_drivers_only())104 return -ENODEV;105 106 return platform_driver_register(platform_drv);107}108 109/**110 * drm_module_platform_driver - Register a DRM driver for platform devices111 * @__platform_drv: the platform driver structure112 *113 * Registers a DRM driver for devices on the platform bus. The helper114 * macro behaves like module_platform_driver() but tests the state of115 * drm_firmware_drivers_only(). For more complex module initialization,116 * use module_init() and module_exit() directly.117 *118 * Each module may only use this macro once. Calling it replaces119 * module_init() and module_exit().120 */121#define drm_module_platform_driver(__platform_drv) \122 module_driver(__platform_drv, drm_platform_driver_register, \123 platform_driver_unregister)124 125#endif126