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