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