1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2021 Intel Corporation 4 */ 5 6 #include "xe_module.h" 7 8 #include <linux/init.h> 9 #include <linux/module.h> 10 11 #include <drm/drm_module.h> 12 13 #include "xe_drv.h" 14 #include "xe_configfs.h" 15 #include "xe_hw_fence.h" 16 #include "xe_pci.h" 17 #include "xe_pm.h" 18 #include "xe_observation.h" 19 #include "xe_sched_job.h" 20 21 #if IS_ENABLED(CONFIG_DRM_XE_DEBUG) 22 #define DEFAULT_GUC_LOG_LEVEL 3 23 #else 24 #define DEFAULT_GUC_LOG_LEVEL 1 25 #endif 26 27 #define DEFAULT_PROBE_DISPLAY true 28 #define DEFAULT_VRAM_BAR_SIZE 0 29 #define DEFAULT_FORCE_PROBE CONFIG_DRM_XE_FORCE_PROBE 30 #define DEFAULT_MAX_VFS ~0 31 #define DEFAULT_MAX_VFS_STR "unlimited" 32 #define DEFAULT_WEDGED_MODE 1 33 #define DEFAULT_SVM_NOTIFIER_SIZE 512 34 35 struct xe_modparam xe_modparam = { 36 .probe_display = DEFAULT_PROBE_DISPLAY, 37 .guc_log_level = DEFAULT_GUC_LOG_LEVEL, 38 .force_probe = DEFAULT_FORCE_PROBE, 39 #ifdef CONFIG_PCI_IOV 40 .max_vfs = DEFAULT_MAX_VFS, 41 #endif 42 .wedged_mode = DEFAULT_WEDGED_MODE, 43 .svm_notifier_size = DEFAULT_SVM_NOTIFIER_SIZE, 44 /* the rest are 0 by default */ 45 }; 46 47 module_param_named(svm_notifier_size, xe_modparam.svm_notifier_size, uint, 0600); 48 MODULE_PARM_DESC(svm_notifier_size, "Set the svm notifier size in MiB, must be power of 2 " 49 "[default=" __stringify(DEFAULT_SVM_NOTIFIER_SIZE) "]"); 50 51 module_param_named_unsafe(force_execlist, xe_modparam.force_execlist, bool, 0444); 52 MODULE_PARM_DESC(force_execlist, "Force Execlist submission"); 53 54 module_param_named(probe_display, xe_modparam.probe_display, bool, 0444); 55 MODULE_PARM_DESC(probe_display, "Probe display HW, otherwise it's left untouched " 56 "[default=" __stringify(DEFAULT_PROBE_DISPLAY) "])"); 57 58 module_param_named(vram_bar_size, xe_modparam.force_vram_bar_size, int, 0600); 59 MODULE_PARM_DESC(vram_bar_size, "Set the vram bar size in MiB (<0=disable-resize, 0=max-needed-size, >0=force-size " 60 "[default=" __stringify(DEFAULT_VRAM_BAR_SIZE) "])"); 61 62 module_param_named(guc_log_level, xe_modparam.guc_log_level, int, 0600); 63 MODULE_PARM_DESC(guc_log_level, "GuC firmware logging level (0=disable, 1=normal, 2..5=verbose-levels " 64 "[default=" __stringify(DEFAULT_GUC_LOG_LEVEL) "])"); 65 66 module_param_named_unsafe(guc_firmware_path, xe_modparam.guc_firmware_path, charp, 0400); 67 MODULE_PARM_DESC(guc_firmware_path, 68 "GuC firmware path to use instead of the default one"); 69 70 module_param_named_unsafe(huc_firmware_path, xe_modparam.huc_firmware_path, charp, 0400); 71 MODULE_PARM_DESC(huc_firmware_path, 72 "HuC firmware path to use instead of the default one - empty string disables"); 73 74 module_param_named_unsafe(gsc_firmware_path, xe_modparam.gsc_firmware_path, charp, 0400); 75 MODULE_PARM_DESC(gsc_firmware_path, 76 "GSC firmware path to use instead of the default one - empty string disables"); 77 78 module_param_named_unsafe(force_probe, xe_modparam.force_probe, charp, 0400); 79 MODULE_PARM_DESC(force_probe, 80 "Force probe options for specified devices. See CONFIG_DRM_XE_FORCE_PROBE for details " 81 "[default=" DEFAULT_FORCE_PROBE "])"); 82 83 #ifdef CONFIG_PCI_IOV 84 module_param_named(max_vfs, xe_modparam.max_vfs, uint, 0400); 85 MODULE_PARM_DESC(max_vfs, 86 "Limit number of Virtual Functions (VFs) that could be managed. " 87 "(0=no VFs; N=allow up to N VFs " 88 "[default=" DEFAULT_MAX_VFS_STR "])"); 89 #endif 90 91 module_param_named_unsafe(wedged_mode, xe_modparam.wedged_mode, int, 0600); 92 MODULE_PARM_DESC(wedged_mode, 93 "Module's default policy for the wedged mode (0=never, 1=upon-critical-errors, 2=upon-any-hang " 94 "[default=" __stringify(DEFAULT_WEDGED_MODE) "])"); 95 96 static int xe_check_nomodeset(void) 97 { 98 if (drm_firmware_drivers_only()) 99 return -ENODEV; 100 101 return 0; 102 } 103 104 struct init_funcs { 105 int (*init)(void); 106 void (*exit)(void); 107 }; 108 109 static const struct init_funcs init_funcs[] = { 110 { 111 .init = xe_check_nomodeset, 112 }, 113 { 114 .init = xe_configfs_init, 115 .exit = xe_configfs_exit, 116 }, 117 { 118 .init = xe_hw_fence_module_init, 119 .exit = xe_hw_fence_module_exit, 120 }, 121 { 122 .init = xe_sched_job_module_init, 123 .exit = xe_sched_job_module_exit, 124 }, 125 { 126 .init = xe_register_pci_driver, 127 .exit = xe_unregister_pci_driver, 128 }, 129 { 130 .init = xe_observation_sysctl_register, 131 .exit = xe_observation_sysctl_unregister, 132 }, 133 { 134 .init = xe_pm_module_init, 135 }, 136 }; 137 138 static int __init xe_call_init_func(unsigned int i) 139 { 140 if (WARN_ON(i >= ARRAY_SIZE(init_funcs))) 141 return 0; 142 if (!init_funcs[i].init) 143 return 0; 144 145 return init_funcs[i].init(); 146 } 147 148 static void xe_call_exit_func(unsigned int i) 149 { 150 if (WARN_ON(i >= ARRAY_SIZE(init_funcs))) 151 return; 152 if (!init_funcs[i].exit) 153 return; 154 155 init_funcs[i].exit(); 156 } 157 158 static int __init xe_init(void) 159 { 160 int err, i; 161 162 for (i = 0; i < ARRAY_SIZE(init_funcs); i++) { 163 err = xe_call_init_func(i); 164 if (err) { 165 while (i--) 166 xe_call_exit_func(i); 167 return err; 168 } 169 } 170 171 return 0; 172 } 173 174 static void __exit xe_exit(void) 175 { 176 int i; 177 178 for (i = ARRAY_SIZE(init_funcs) - 1; i >= 0; i--) 179 xe_call_exit_func(i); 180 } 181 182 module_init(xe_init); 183 module_exit(xe_exit); 184 185 MODULE_AUTHOR("Intel Corporation"); 186 187 MODULE_DESCRIPTION(DRIVER_DESC); 188 MODULE_LICENSE("GPL and additional rights"); 189