xref: /openbmc/linux/include/drm/drm_module.h (revision 09f137c3)
152506b09SThomas Zimmermann /* SPDX-License-Identifier: MIT */
252506b09SThomas Zimmermann 
352506b09SThomas Zimmermann #ifndef DRM_MODULE_H
452506b09SThomas Zimmermann #define DRM_MODULE_H
552506b09SThomas Zimmermann 
652506b09SThomas Zimmermann #include <linux/pci.h>
7*09f137c3SJavier Martinez Canillas #include <linux/platform_device.h>
852506b09SThomas Zimmermann 
952506b09SThomas Zimmermann #include <drm/drm_drv.h>
1052506b09SThomas Zimmermann 
1152506b09SThomas Zimmermann /**
1252506b09SThomas Zimmermann  * DOC: overview
1352506b09SThomas Zimmermann  *
1452506b09SThomas Zimmermann  * This library provides helpers registering DRM drivers during module
1552506b09SThomas Zimmermann  * initialization and shutdown. The provided helpers act like bus-specific
1652506b09SThomas Zimmermann  * module helpers, such as module_pci_driver(), but respect additional
1752506b09SThomas Zimmermann  * parameters that control DRM driver registration.
1852506b09SThomas Zimmermann  *
1952506b09SThomas Zimmermann  * Below is an example of initializing a DRM driver for a device on the
2052506b09SThomas Zimmermann  * PCI bus.
2152506b09SThomas Zimmermann  *
2252506b09SThomas Zimmermann  * .. code-block:: c
2352506b09SThomas Zimmermann  *
2452506b09SThomas Zimmermann  *	struct pci_driver my_pci_drv = {
2552506b09SThomas Zimmermann  *	};
2652506b09SThomas Zimmermann  *
2752506b09SThomas Zimmermann  *	drm_module_pci_driver(my_pci_drv);
2852506b09SThomas Zimmermann  *
2952506b09SThomas Zimmermann  * The generated code will test if DRM drivers are enabled and register
3052506b09SThomas Zimmermann  * the PCI driver my_pci_drv. For more complex module initialization, you
3152506b09SThomas Zimmermann  * can still use module_init() and module_exit() in your driver.
3252506b09SThomas Zimmermann  */
3352506b09SThomas Zimmermann 
3452506b09SThomas Zimmermann /*
3552506b09SThomas Zimmermann  * PCI drivers
3652506b09SThomas Zimmermann  */
3752506b09SThomas Zimmermann 
drm_pci_register_driver(struct pci_driver * pci_drv)3852506b09SThomas Zimmermann static inline int __init drm_pci_register_driver(struct pci_driver *pci_drv)
3952506b09SThomas Zimmermann {
4052506b09SThomas Zimmermann 	if (drm_firmware_drivers_only())
4152506b09SThomas Zimmermann 		return -ENODEV;
4252506b09SThomas Zimmermann 
4352506b09SThomas Zimmermann 	return pci_register_driver(pci_drv);
4452506b09SThomas Zimmermann }
4552506b09SThomas Zimmermann 
4652506b09SThomas Zimmermann /**
4752506b09SThomas Zimmermann  * drm_module_pci_driver - Register a DRM driver for PCI-based devices
4852506b09SThomas Zimmermann  * @__pci_drv: the PCI driver structure
4952506b09SThomas Zimmermann  *
5052506b09SThomas Zimmermann  * Registers a DRM driver for devices on the PCI bus. The helper
5152506b09SThomas Zimmermann  * macro behaves like module_pci_driver() but tests the state of
5252506b09SThomas Zimmermann  * drm_firmware_drivers_only(). For more complex module initialization,
5352506b09SThomas Zimmermann  * use module_init() and module_exit() directly.
5452506b09SThomas Zimmermann  *
5552506b09SThomas Zimmermann  * Each module may only use this macro once. Calling it replaces
5652506b09SThomas Zimmermann  * module_init() and module_exit().
5752506b09SThomas Zimmermann  */
5852506b09SThomas Zimmermann #define drm_module_pci_driver(__pci_drv) \
5952506b09SThomas Zimmermann 	module_driver(__pci_drv, drm_pci_register_driver, pci_unregister_driver)
6052506b09SThomas Zimmermann 
6152506b09SThomas Zimmermann static inline int __init
drm_pci_register_driver_if_modeset(struct pci_driver * pci_drv,int modeset)6252506b09SThomas Zimmermann drm_pci_register_driver_if_modeset(struct pci_driver *pci_drv, int modeset)
6352506b09SThomas Zimmermann {
6452506b09SThomas Zimmermann 	if (drm_firmware_drivers_only() && modeset == -1)
6552506b09SThomas Zimmermann 		return -ENODEV;
6652506b09SThomas Zimmermann 	if (modeset == 0)
6752506b09SThomas Zimmermann 		return -ENODEV;
6852506b09SThomas Zimmermann 
6952506b09SThomas Zimmermann 	return pci_register_driver(pci_drv);
7052506b09SThomas Zimmermann }
7152506b09SThomas Zimmermann 
7252506b09SThomas Zimmermann static inline void __exit
drm_pci_unregister_driver_if_modeset(struct pci_driver * pci_drv,int modeset)7352506b09SThomas Zimmermann drm_pci_unregister_driver_if_modeset(struct pci_driver *pci_drv, int modeset)
7452506b09SThomas Zimmermann {
7552506b09SThomas Zimmermann 	pci_unregister_driver(pci_drv);
7652506b09SThomas Zimmermann }
7752506b09SThomas Zimmermann 
7852506b09SThomas Zimmermann /**
7952506b09SThomas Zimmermann  * drm_module_pci_driver_if_modeset - Register a DRM driver for PCI-based devices
8052506b09SThomas Zimmermann  * @__pci_drv: the PCI driver structure
8152506b09SThomas Zimmermann  * @__modeset: an additional parameter that disables the driver
8252506b09SThomas Zimmermann  *
8352506b09SThomas Zimmermann  * This macro is deprecated and only provided for existing drivers. For
8452506b09SThomas Zimmermann  * new drivers, use drm_module_pci_driver().
8552506b09SThomas Zimmermann  *
8652506b09SThomas Zimmermann  * Registers a DRM driver for devices on the PCI bus. The helper macro
8752506b09SThomas Zimmermann  * behaves like drm_module_pci_driver() with an additional driver-specific
8852506b09SThomas Zimmermann  * flag. If __modeset is 0, the driver has been disabled, if __modeset is
8952506b09SThomas Zimmermann  * -1 the driver state depends on the global DRM state. For all other
9052506b09SThomas Zimmermann  * values, the PCI driver has been enabled. The default should be -1.
9152506b09SThomas Zimmermann  */
9252506b09SThomas Zimmermann #define drm_module_pci_driver_if_modeset(__pci_drv, __modeset) \
9352506b09SThomas Zimmermann 	module_driver(__pci_drv, drm_pci_register_driver_if_modeset, \
9452506b09SThomas Zimmermann 		      drm_pci_unregister_driver_if_modeset, __modeset)
9552506b09SThomas Zimmermann 
96*09f137c3SJavier Martinez Canillas /*
97*09f137c3SJavier Martinez Canillas  * Platform drivers
98*09f137c3SJavier Martinez Canillas  */
99*09f137c3SJavier Martinez Canillas 
100*09f137c3SJavier Martinez Canillas static inline int __init
drm_platform_driver_register(struct platform_driver * platform_drv)101*09f137c3SJavier Martinez Canillas drm_platform_driver_register(struct platform_driver *platform_drv)
102*09f137c3SJavier Martinez Canillas {
103*09f137c3SJavier Martinez Canillas 	if (drm_firmware_drivers_only())
104*09f137c3SJavier Martinez Canillas 		return -ENODEV;
105*09f137c3SJavier Martinez Canillas 
106*09f137c3SJavier Martinez Canillas 	return platform_driver_register(platform_drv);
107*09f137c3SJavier Martinez Canillas }
108*09f137c3SJavier Martinez Canillas 
109*09f137c3SJavier Martinez Canillas /**
110*09f137c3SJavier Martinez Canillas  * drm_module_platform_driver - Register a DRM driver for platform devices
111*09f137c3SJavier Martinez Canillas  * @__platform_drv: the platform driver structure
112*09f137c3SJavier Martinez Canillas  *
113*09f137c3SJavier Martinez Canillas  * Registers a DRM driver for devices on the platform bus. The helper
114*09f137c3SJavier Martinez Canillas  * macro behaves like module_platform_driver() but tests the state of
115*09f137c3SJavier Martinez Canillas  * drm_firmware_drivers_only(). For more complex module initialization,
116*09f137c3SJavier Martinez Canillas  * use module_init() and module_exit() directly.
117*09f137c3SJavier Martinez Canillas  *
118*09f137c3SJavier Martinez Canillas  * Each module may only use this macro once. Calling it replaces
119*09f137c3SJavier Martinez Canillas  * module_init() and module_exit().
120*09f137c3SJavier Martinez Canillas  */
121*09f137c3SJavier Martinez Canillas #define drm_module_platform_driver(__platform_drv) \
122*09f137c3SJavier Martinez Canillas 	module_driver(__platform_drv, drm_platform_driver_register, \
123*09f137c3SJavier Martinez Canillas 		      platform_driver_unregister)
124*09f137c3SJavier Martinez Canillas 
12552506b09SThomas Zimmermann #endif
126