drm: Add DRM module helpers for existing PCI drivers
Subsystems (11)
Thomas Zimmermann
maintainercover drm: Add DRM module helpers for existing PCI drivers
This is an RFC patchset to complement the helper macros provided in [1]. The module helpers create module init and exit helpers that respect the kernel parameters that enable/disable DRM drivers.
There's one more patch that prepares qxl by moving some code around. It's required to make use of the helpers from within qxl.
Javier, please see if you find anything useful here and cherry-pick into your patchset. The driver changes should complement the ones in your patchset. The module macros are similar to yours and should be easily mergable.
I tested the macros with ast.
[1] https://patchwork.freedesktop.org/series/98162/
Thomas Zimmermann (10):
drm: Provide PCI module-init macros
drm/ast: Replace module-init boiler-plate code with DRM helpers drm/bochs: Replace module-init boiler-plate code with DRM helpers drm/cirrus: Replace module-init boiler-plate code with DRM helpers drm/hisilicon/hibmc: Replace module initialization with DRM helpers drm/mgag200: Replace module-init boiler-plate code with DRM helpers drm/qxl: Move ioctl array next to its only user
drm/qxl: Replace module-init boiler-plate code with DRM helpers drm/vboxvideo: Replace module-init boiler-plate code with DRM helpers drm/vmwgfx: Replace module-init boiler-plate code with DRM helpers
Documentation/gpu/drm-internals.rst | 6 ++ drivers/gpu/drm/ast/ast_drv.c | 18 +--- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 3 +- drivers/gpu/drm/mgag200/mgag200_drv.c | 20 +--- drivers/gpu/drm/qxl/qxl_drv.c | 31 +++--- drivers/gpu/drm/qxl/qxl_drv.h | 13 ++- drivers/gpu/drm/qxl/qxl_ioctl.c | 41 ++------ drivers/gpu/drm/tiny/bochs.c | 20 +--- drivers/gpu/drm/tiny/cirrus.c | 17 +--- drivers/gpu/drm/vboxvideo/vbox_drv.c | 20 +--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 24 +---- include/drm/drm_module.h | 95 +++++++++++++++++++ 12 files changed, 145 insertions(+), 163 deletions(-) create mode 100644 include/drm/drm_module.h
base-commit: 3f422828221d9ceefcddef0be33561b1646a1cbe --
2.34.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH 1/10 drm: Provide PCI module-init macros
Provide helper macros to register PCI-based DRM drivers. The new macros behave like module_pci_driver() with an additional test if DRM modesetting has been enabled.
--- Documentation/gpu/drm-internals.rst | 6 ++ include/drm/drm_module.h | 95 +++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 include/drm/drm_module.h
Documentation/gpu/drm-internals.rst +6 -0
@@ -75,6 +75,12 @@ update it, its value is mostly useless. The DRM core prints it to the kernel log at initialization time and passes it to userspace through the DRM_IOCTL_VERSION ioctl. +Module Initialization +--------------------- + +.. kernel-doc:: include/drm/drm_module.h + :doc: overview + Managing Ownership of the Framebuffer Aperture ----------------------------------------------
include/drm/drm_module.h new file +95 -0
95 lines not on this page · raw message
Signature · 6 lines
2.34.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH 2/10 drm/ast: Replace module-init boiler-plate code with DRM helpers
In reply to Thomas ZimmermannRemove custom ast_init() and ast_exit() functions and initialize the module with DRM module helpers.
--- drivers/gpu/drm/ast/ast_drv.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)
drivers/gpu/drm/ast/ast_drv.c +2 -16
@@ -34,6 +34,7 @@#include <drm/drm_crtc_helper.h> #include <drm/drm_drv.h> #include <drm/drm_gem_vram_helper.h> +#include <drm/drm_module.h> #include <drm/drm_probe_helper.h> #include "ast_drv.h"
@@ -230,22 +231,7 @@ static struct pci_driver ast_pci_driver = { .driver.pm = &ast_pm_ops, }; -static int __init ast_init (void ) -{ -if (drm_firmware_drivers_only () && ast_modeset ==-1 ) -return -EINVAL ; - -if (ast_modeset ==0 ) -return -EINVAL ; -return pci_register_driver (&ast_pci_driver); -} -static void __exit ast_exit(void) -{ -pci_unregister_driver (&ast_pci_driver); -} - -module_init (ast_init); -module_exit (ast_exit); +drm_module_pci_driver_if_modeset (ast_pci_driver, ast_modeset);MODULE_AUTHOR (DRIVER_AUTHOR );MODULE_DESCRIPTION (DRIVER_DESC );
Signature · 1 line
2.34.1
Thomas Zimmermann
maintainerPATCH 3/10 drm/bochs: Replace module-init boiler-plate code with DRM helpers
In reply to Thomas ZimmermannRemove custom bochs_init() and bochs_exit() functions and initialize the module with DRM module helpers.
--- drivers/gpu/drm/tiny/bochs.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)
drivers/gpu/drm/tiny/bochs.c +2 -18
@@ -10,6 +10,7 @@#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_gem_vram_helper.h> #include <drm/drm_managed.h> +#include <drm/drm_module.h> #include <drm/drm_probe_helper.h> #include <drm/drm_simple_kms_helper.h>
@@ -716,24 +717,7 @@ static struct pci_driver bochs_pci_driver = {/* ---------------------------------------------------------------------- */ /* module init/exit */ -static int __init bochs_init (void ) -{ -if (drm_firmware_drivers_only () && bochs_modeset ==-1 ) -return -EINVAL ; - -if (bochs_modeset ==0 ) -return -EINVAL ; - -return pci_register_driver (&bochs_pci_driver); -} - -static void __exit bochs_exit(void) -{ -pci_unregister_driver (&bochs_pci_driver); -} - -module_init (bochs_init); -module_exit (bochs_exit); +drm_module_pci_driver_if_modeset (bochs_pci_driver, bochs_modeset);MODULE_DEVICE_TABLE (pci, bochs_pci_tbl);MODULE_AUTHOR ("Gerd Hoffmann <[email protected]>" );
Signature · 6 lines
2.34.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH 4/10 drm/cirrus: Replace module-init boiler-plate code with DRM helpers
In reply to Thomas ZimmermannRemove custom cirrus_init() and cirrus_exit() functions and initialize the module with DRM module helpers.
--- drivers/gpu/drm/tiny/cirrus.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/gpu/drm/tiny/cirrus.c +2 -15
@@ -39,6 +39,7 @@#include <drm/drm_ioctl.h> #include <drm/drm_managed.h> #include <drm/drm_modeset_helper_vtables.h> +#include <drm/drm_module.h> #include <drm/drm_probe_helper.h> #include <drm/drm_simple_kms_helper.h>
@@ -633,21 +634,7 @@ static struct pci_driver cirrus_pci_driver = { .remove = cirrus_pci_remove, }; -static int __init cirrus_init (void ) -{ -if (drm_firmware_drivers_only ()) -return -EINVAL ; - -return pci_register_driver (&cirrus_pci_driver); -} - -static void __exit cirrus_exit(void) -{ -pci_unregister_driver (&cirrus_pci_driver); -} - -module_init (cirrus_init); -module_exit (cirrus_exit); +drm_module_pci_driver (cirrus_pci_driver)MODULE_DEVICE_TABLE (pci, pciidlist);MODULE_LICENSE ("GPL" );
Signature · 6 lines
2.34.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH 5/10 drm/hisilicon/hibmc: Replace module initialization with DRM helpers
In reply to Thomas ZimmermannReplace module_pci_driver() with drm_module_pci_driver(). The DRM macro respects drm_firmware_drivers_only() and fails if the flag has been set.
--- drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +2 -1
@@ -20,6 +20,7 @@#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_gem_vram_helper.h> #include <drm/drm_managed.h> +#include <drm/drm_module.h> #include <drm/drm_vblank.h> #include "hibmc_drm_drv.h"
@@ -379,7 +380,7 @@ static struct pci_driver hibmc_pci_driver = { .driver.pm = &hibmc_pm_ops, }; -module_pci_driver (hibmc_pci_driver); +drm_module_pci_driver (hibmc_pci_driver);MODULE_DEVICE_TABLE (pci, hibmc_pci_table);MODULE_AUTHOR ("RongrongZou <[email protected]>" );
Signature · 6 lines
2.34.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH 6/10 drm/mgag200: Replace module-init boiler-plate code with DRM helpers
In reply to Thomas ZimmermannRemove custom mgag200_init() and mgag200_exit() functions and initialize the module with DRM_module helpers.
--- drivers/gpu/drm/mgag200/mgag200_drv.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)
drivers/gpu/drm/mgag200/mgag200_drv.c +2 -18
@@ -14,6 +14,7 @@#include <drm/drm_drv.h> #include <drm/drm_file.h> #include <drm/drm_ioctl.h> +#include <drm/drm_module.h> #include <drm/drm_pciids.h> #include "mgag200_drv.h"
@@ -375,24 +376,7 @@ static struct pci_driver mgag200_pci_driver = { .remove = mgag200_pci_remove, }; -static int __init mgag200_init (void ) -{ -if (drm_firmware_drivers_only () && mgag200_modeset ==-1 ) -return -EINVAL ; - -if (mgag200_modeset ==0 ) -return -EINVAL ; - -return pci_register_driver (&mgag200_pci_driver); -} - -static void __exit mgag200_exit(void) -{ -pci_unregister_driver (&mgag200_pci_driver); -} - -module_init (mgag200_init); -module_exit (mgag200_exit); +drm_module_pci_driver_if_modeset (mgag200_pci_driver, mgag200_modeset);MODULE_AUTHOR (DRIVER_AUTHOR );MODULE_DESCRIPTION (DRIVER_DESC );
Signature · 6 lines
2.34.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH 7/10 drm/qxl: Move ioctl array next to its only user
In reply to Thomas ZimmermannMove the array qxl_ioctl to qxl_drv.c and initialize the num_ioctls field of struct drm_driver at runtime. Replaces the current fragile ioctl setup and allows for generating the module init/exit code.
--- drivers/gpu/drm/qxl/qxl_drv.c | 12 +++++++++- drivers/gpu/drm/qxl/qxl_drv.h | 13 +++++++---- drivers/gpu/drm/qxl/qxl_ioctl.c | 41 ++++++--------------------------- 3 files changed, 27 insertions(+), 39 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +11 -1
@@ -269,6 +269,16 @@ static struct pci_driver qxl_pci_driver = { .driver.pm = &qxl_pm_ops, }; +static const struct drm_ioctl_desc qxl_ioctls[] = { +DRM_IOCTL_DEF_DRV (QXL_ALLOC , qxl_alloc_ioctl,DRM_AUTH ), +DRM_IOCTL_DEF_DRV (QXL_MAP , qxl_map_ioctl,DRM_AUTH ), +DRM_IOCTL_DEF_DRV (QXL_EXECBUFFER , qxl_execbuffer_ioctl,DRM_AUTH ), +DRM_IOCTL_DEF_DRV (QXL_UPDATE_AREA , qxl_update_area_ioctl,DRM_AUTH ), +DRM_IOCTL_DEF_DRV (QXL_GETPARAM , qxl_getparam_ioctl,DRM_AUTH ), +DRM_IOCTL_DEF_DRV (QXL_CLIENTCAP , qxl_clientcap_ioctl,DRM_AUTH ), +DRM_IOCTL_DEF_DRV (QXL_ALLOC_SURF , qxl_alloc_surf_ioctl,DRM_AUTH ), +}; +static struct drm_driver qxl_driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET |DRIVER_ATOMIC ,
@@ -282,6 +292,7 @@ static struct drm_driver qxl_driver = { .gem_prime_import_sg_table = qxl_gem_prime_import_sg_table, .fops = &qxl_fops, .ioctls = qxl_ioctls, + .num_ioctls = ARRAY_SIZE(qxl_ioctls), .name = DRIVER_NAME, .desc = DRIVER_DESC, .date = DRIVER_DATE,
@@ -299,7 +310,6 @@ static int __init qxl_init(void)if (qxl_modeset ==0 )return -EINVAL ; - qxl_driver.num_ioctls = qxl_max_ioctls;return pci_register_driver (&qxl_pci_driver); }
drivers/gpu/drm/qxl/qxl_drv.h +9 -4
@@ -65,7 +65,6 @@ struct dma_buf_map;#define QXL_DEBUGFS_MAX_COMPONENTS 32extern int qxl_num_crtc; -extern int qxl_max_ioctls;#define QXL_INTERRUPT_MASK (\ QXL_INTERRUPT_DISPLAY |\
@@ -261,9 +260,6 @@ struct qxl_device {int qxl_debugfs_fence_init (struct qxl_device *rdev); -extern const struct drm_ioctl_desc qxl_ioctls[]; -extern int qxl_max_ioctl; -int qxl_device_init (struct qxl_device *qdev,struct pci_dev *pdev);void qxl_device_fini (struct qxl_device *qdev);
@@ -457,4 +453,13 @@ struct qxl_drv_surface * qxl_surface_lookup(struct drm_device *dev, int surface_id);void qxl_surface_evict (struct qxl_device *qdev,struct qxl_bo *surf,bool freeing); +/* qxl_ioctl.c */ +int qxl_alloc_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv); +int qxl_map_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv); +int qxl_execbuffer_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv); +int qxl_update_area_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int qxl_getparam_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv); +int qxl_clientcap_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv); +int qxl_alloc_surf_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +#endif
drivers/gpu/drm/qxl/qxl_ioctl.c +7 -34
86 lines not on this page · raw message
Signature · 6 lines
2.34.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH 8/10 drm/qxl: Replace module-init boiler-plate code with DRM helpers
In reply to Thomas ZimmermannRemove custom qxl_init() and qxl_exit() functions and initialize the module with DRM module helpers.
--- drivers/gpu/drm/qxl/qxl_drv.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.c +2 -17
@@ -39,6 +39,7 @@#include <drm/drm_drv.h> #include <drm/drm_file.h> #include <drm/drm_gem_ttm_helper.h> +#include <drm/drm_module.h> #include <drm/drm_modeset_helper.h> #include <drm/drm_prime.h> #include <drm/drm_probe_helper.h>
@@ -303,23 +304,7 @@ static struct drm_driver qxl_driver = { .release = qxl_drm_release, }; -static int __init qxl_init (void ) -{ -if (drm_firmware_drivers_only () && qxl_modeset ==-1 ) -return -EINVAL ; - -if (qxl_modeset ==0 ) -return -EINVAL ; -return pci_register_driver (&qxl_pci_driver); -} - -static void __exit qxl_exit(void) -{ -pci_unregister_driver (&qxl_pci_driver); -} - -module_init (qxl_init); -module_exit (qxl_exit); +drm_module_pci_driver_if_modeset (qxl_pci_driver, qxl_modeset);MODULE_AUTHOR (DRIVER_AUTHOR );MODULE_DESCRIPTION (DRIVER_DESC );
Signature · 6 lines
2.34.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH 9/10 drm/vboxvideo: Replace module-init boiler-plate code with DRM helpers
In reply to Thomas ZimmermannRemove custom vbox_init() and vbox_exit() functions and initialize the module with DRM module helpers.
--- drivers/gpu/drm/vboxvideo/vbox_drv.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)
drivers/gpu/drm/vboxvideo/vbox_drv.c +2 -18
@@ -18,6 +18,7 @@#include <drm/drm_file.h> #include <drm/drm_ioctl.h> #include <drm/drm_managed.h> +#include <drm/drm_module.h> #include "vbox_drv.h"
@@ -190,24 +191,7 @@ static const struct drm_driver driver = { DRM_GEM_VRAM_DRIVER, }; -static int __init vbox_init (void ) -{ -if (drm_firmware_drivers_only () && vbox_modeset ==-1 ) -return -EINVAL ; - -if (vbox_modeset ==0 ) -return -EINVAL ; - -return pci_register_driver (&vbox_pci_driver); -} - -static void __exit vbox_exit(void) -{ -pci_unregister_driver (&vbox_pci_driver); -} - -module_init (vbox_init); -module_exit (vbox_exit); +drm_module_pci_driver_if_modeset (vbox_pci_driver, vbox_modeset);MODULE_AUTHOR ("Oracle Corporation" );MODULE_AUTHOR ("Hans de Goede <[email protected]>" );
Signature · 6 lines
2.34.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH 10/10 drm/vmwgfx: Replace module-init boiler-plate code with DRM helpers
In reply to Thomas ZimmermannRemove custom vmwgfx_init() and vmwgfx_exit() functions and initialize the module with DRM_module helpers.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +3 -21
@@ -32,9 +32,10 @@#include <drm/drm_aperture.h> #include <drm/drm_drv.h> +#include <drm/drm_gem_ttm_helper.h> #include <drm/drm_ioctl.h> +#include <drm/drm_module.h> #include <drm/drm_sysfs.h> -#include <drm/drm_gem_ttm_helper.h> #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_range_manager.h> #include <drm/ttm/ttm_placement.h>
@@ -1651,26 +1652,7 @@ static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return ret; } -static int __init vmwgfx_init (void ) -{ -int ret; - -if (drm_firmware_drivers_only ()) -return -EINVAL ; - - ret =pci_register_driver (&vmw_pci_driver); -if (ret) -DRM_ERROR ("Failed initializing DRM.\n" ); -return ret; -} - -static void __exit vmwgfx_exit(void) -{ -pci_unregister_driver (&vmw_pci_driver); -} - -module_init (vmwgfx_init); -module_exit (vmwgfx_exit); +drm_module_pci_driver (vmw_pci_driver);MODULE_AUTHOR ("VMware Inc. and others" );MODULE_DESCRIPTION ("Standalone drm driver for the VMware SVGA device" );
Signature · 6 lines
2.34.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 16 lines · Thomas Zimmermann
This is an RFC patchset to complement the helper macros provided in [1]. The module helpers create module init and exit helpers that respect the kernel parameters that enable/disable DRM drivers.
There's one more patch that prepares qxl by moving some code around. It's required to make use of the helpers from within qxl.
Javier, please see if you find anything useful here and cherry-pick into your patchset. The driver changes should complement the ones in your patchset. The module macros are similar to yours and should be easily mergable.
I tested the macros with ast.
Quoted 12 lines
Thomas Zimmermann (10):
drm: Provide PCI module-init macros
drm/ast: Replace module-init boiler-plate code with DRM helpers drm/bochs: Replace module-init boiler-plate code with DRM helpers drm/cirrus: Replace module-init boiler-plate code with DRM helpers drm/hisilicon/hibmc: Replace module initialization with DRM helpers drm/mgag200: Replace module-init boiler-plate code with DRM helpers drm/qxl: Move ioctl array next to its only user
drm/qxl: Replace module-init boiler-plate code with DRM helpers drm/vboxvideo: Replace module-init boiler-plate code with DRM helpers drm/vmwgfx: Replace module-init boiler-plate code with DRM helpers
Pushed the remaining of these patches to drm-misc-next. Thanks!
Best regards,
Signature · 3 lines
Javier Martinez Canillas Linux Engineering Red Hat