Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe: Support 'nomodeset' kernel command-line option

Setting 'nomodeset' on the kernel command line disables all graphics
drivers with modesetting capabilities, leaving only firmware drivers,
such as simpledrm or efifb.

Most DRM drivers automatically support 'nomodeset' via DRM's module
helper macros. In xe, which uses regular module_init(), manually call
drm_firmware_drivers_only() to test for 'nomodeset'. Do not register
the driver if set.

v2:
- use xe's init table (Lucas)
- do NULL test for init/exit functions

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240827121003.97429-1-tzimmermann@suse.de
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>

authored by

Thomas Zimmermann and committed by
Lucas De Marchi
014125c6 8a04e342

+36 -3
+36 -3
drivers/gpu/drm/xe/xe_module.c
··· 8 8 #include <linux/init.h> 9 9 #include <linux/module.h> 10 10 11 + #include <drm/drm_module.h> 12 + 11 13 #include "xe_drv.h" 12 14 #include "xe_hw_fence.h" 13 15 #include "xe_pci.h" ··· 63 61 MODULE_PARM_DESC(wedged_mode, 64 62 "Module's default policy for the wedged mode - 0=never, 1=upon-critical-errors[default], 2=upon-any-hang"); 65 63 64 + static int xe_check_nomodeset(void) 65 + { 66 + if (drm_firmware_drivers_only()) 67 + return -ENODEV; 68 + 69 + return 0; 70 + } 71 + 66 72 struct init_funcs { 67 73 int (*init)(void); 68 74 void (*exit)(void); 69 75 }; 70 76 71 77 static const struct init_funcs init_funcs[] = { 78 + { 79 + .init = xe_check_nomodeset, 80 + }, 72 81 { 73 82 .init = xe_hw_fence_module_init, 74 83 .exit = xe_hw_fence_module_exit, ··· 98 85 }, 99 86 }; 100 87 88 + static int __init xe_call_init_func(unsigned int i) 89 + { 90 + if (WARN_ON(i >= ARRAY_SIZE(init_funcs))) 91 + return 0; 92 + if (!init_funcs[i].init) 93 + return 0; 94 + 95 + return init_funcs[i].init(); 96 + } 97 + 98 + static void xe_call_exit_func(unsigned int i) 99 + { 100 + if (WARN_ON(i >= ARRAY_SIZE(init_funcs))) 101 + return; 102 + if (!init_funcs[i].exit) 103 + return; 104 + 105 + init_funcs[i].exit(); 106 + } 107 + 101 108 static int __init xe_init(void) 102 109 { 103 110 int err, i; 104 111 105 112 for (i = 0; i < ARRAY_SIZE(init_funcs); i++) { 106 - err = init_funcs[i].init(); 113 + err = xe_call_init_func(i); 107 114 if (err) { 108 115 while (i--) 109 - init_funcs[i].exit(); 116 + xe_call_exit_func(i); 110 117 return err; 111 118 } 112 119 } ··· 139 106 int i; 140 107 141 108 for (i = ARRAY_SIZE(init_funcs) - 1; i >= 0; i--) 142 - init_funcs[i].exit(); 109 + xe_call_exit_func(i); 143 110 } 144 111 145 112 module_init(xe_init);