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 #include <linux/workqueue.h> 11 12 #include <drm/drm_module.h> 13 14 #include "xe_defaults.h" 15 #include "xe_device_types.h" 16 #include "xe_drv.h" 17 #include "xe_configfs.h" 18 #include "xe_hw_fence.h" 19 #include "xe_pci.h" 20 #include "xe_pm.h" 21 #include "xe_observation.h" 22 #include "xe_sched_job.h" 23 24 struct xe_modparam xe_modparam = { 25 .probe_display = XE_DEFAULT_PROBE_DISPLAY, 26 .guc_log_level = XE_DEFAULT_GUC_LOG_LEVEL, 27 .force_probe = XE_DEFAULT_FORCE_PROBE, 28 #ifdef CONFIG_PCI_IOV 29 .max_vfs = XE_DEFAULT_MAX_VFS, 30 #endif 31 .wedged_mode = XE_DEFAULT_WEDGED_MODE, 32 .svm_notifier_size = XE_DEFAULT_SVM_NOTIFIER_SIZE, 33 /* the rest are 0 by default */ 34 }; 35 36 module_param_named(svm_notifier_size, xe_modparam.svm_notifier_size, uint, 0600); 37 MODULE_PARM_DESC(svm_notifier_size, "Set the svm notifier size in MiB, must be power of 2 " 38 "[default=" __stringify(XE_DEFAULT_SVM_NOTIFIER_SIZE) "]"); 39 40 module_param_named_unsafe(force_execlist, xe_modparam.force_execlist, bool, 0444); 41 MODULE_PARM_DESC(force_execlist, "Force Execlist submission"); 42 43 #if IS_ENABLED(CONFIG_DRM_XE_DISPLAY) 44 module_param_named(probe_display, xe_modparam.probe_display, bool, 0444); 45 MODULE_PARM_DESC(probe_display, "Probe display HW, otherwise it's left untouched " 46 "[default=" __stringify(XE_DEFAULT_PROBE_DISPLAY) "])"); 47 #endif 48 49 module_param_named(vram_bar_size, xe_modparam.force_vram_bar_size, int, 0600); 50 MODULE_PARM_DESC(vram_bar_size, "Set the vram bar size in MiB (<0=disable-resize, 0=max-needed-size, >0=force-size " 51 "[default=" __stringify(XE_DEFAULT_VRAM_BAR_SIZE) "])"); 52 53 module_param_named(guc_log_level, xe_modparam.guc_log_level, int, 0600); 54 MODULE_PARM_DESC(guc_log_level, "GuC firmware logging level (0=disable, 1=normal, 2..5=verbose-levels " 55 "[default=" __stringify(XE_DEFAULT_GUC_LOG_LEVEL) "])"); 56 57 module_param_named_unsafe(guc_firmware_path, xe_modparam.guc_firmware_path, charp, 0400); 58 MODULE_PARM_DESC(guc_firmware_path, 59 "GuC firmware path to use instead of the default one"); 60 61 module_param_named_unsafe(huc_firmware_path, xe_modparam.huc_firmware_path, charp, 0400); 62 MODULE_PARM_DESC(huc_firmware_path, 63 "HuC firmware path to use instead of the default one - empty string disables"); 64 65 module_param_named_unsafe(gsc_firmware_path, xe_modparam.gsc_firmware_path, charp, 0400); 66 MODULE_PARM_DESC(gsc_firmware_path, 67 "GSC firmware path to use instead of the default one - empty string disables"); 68 69 module_param_named_unsafe(force_probe, xe_modparam.force_probe, charp, 0400); 70 MODULE_PARM_DESC(force_probe, 71 "Force probe options for specified devices. See CONFIG_DRM_XE_FORCE_PROBE for details " 72 "[default=" XE_DEFAULT_FORCE_PROBE "])"); 73 74 #ifdef CONFIG_PCI_IOV 75 module_param_named(max_vfs, xe_modparam.max_vfs, uint, 0400); 76 MODULE_PARM_DESC(max_vfs, 77 "Limit number of Virtual Functions (VFs) that could be managed. " 78 "(0=no VFs; N=allow up to N VFs " 79 "[default=" XE_DEFAULT_MAX_VFS_STR "])"); 80 #endif 81 82 module_param_named_unsafe(wedged_mode, xe_modparam.wedged_mode, uint, 0600); 83 MODULE_PARM_DESC(wedged_mode, 84 "Module's default policy for the wedged mode (0=never, 1=upon-critical-error, 2=upon-any-hang-no-reset " 85 "[default=" XE_DEFAULT_WEDGED_MODE_STR "])"); 86 87 static int xe_check_nomodeset(void) 88 { 89 if (drm_firmware_drivers_only()) 90 return -ENODEV; 91 92 return 0; 93 } 94 95 static struct workqueue_struct *xe_destroy_wq; 96 97 static int __init xe_destroy_wq_module_init(void) 98 { 99 xe_destroy_wq = alloc_workqueue("xe-guc-destroy-wq", WQ_UNBOUND, 0); 100 if (!xe_destroy_wq) 101 return -ENOMEM; 102 return 0; 103 } 104 105 static void xe_destroy_wq_module_exit(void) 106 { 107 if (xe_destroy_wq) 108 destroy_workqueue(xe_destroy_wq); 109 xe_destroy_wq = NULL; 110 } 111 112 /** 113 * xe_destroy_wq_queue() - Queue work on the destroy workqueue 114 * @work: work item to queue 115 * 116 * The destroy workqueue has module lifetime and is used for GuC exec queue 117 * teardown that can outlive a single xe_device. SVM pagemap destroy uses the 118 * per-device xe->destroy_wq instead. 119 * 120 * Return: %true if @work was queued, %false if it was already pending. 121 */ 122 bool xe_destroy_wq_queue(struct work_struct *work) 123 { 124 return queue_work(xe_destroy_wq, work); 125 } 126 127 /** 128 * xe_destroy_wq_flush() - Flush the destroy workqueue 129 * 130 * Drains all pending destroy work. Called from PCI remove to ensure 131 * teardown ordering before the device is destroyed. 132 */ 133 void xe_destroy_wq_flush(void) 134 { 135 if (xe_destroy_wq) 136 flush_workqueue(xe_destroy_wq); 137 } 138 139 struct init_funcs { 140 int (*init)(void); 141 void (*exit)(void); 142 }; 143 144 static const struct init_funcs init_funcs[] = { 145 { 146 .init = xe_check_nomodeset, 147 }, 148 { 149 .init = xe_configfs_init, 150 .exit = xe_configfs_exit, 151 }, 152 { 153 .init = xe_hw_fence_module_init, 154 .exit = xe_hw_fence_module_exit, 155 }, 156 { 157 .init = xe_sched_job_module_init, 158 .exit = xe_sched_job_module_exit, 159 }, 160 { 161 .init = xe_destroy_wq_module_init, 162 .exit = xe_destroy_wq_module_exit, 163 }, 164 { 165 .init = xe_register_pci_driver, 166 .exit = xe_unregister_pci_driver, 167 }, 168 { 169 .init = xe_observation_sysctl_register, 170 .exit = xe_observation_sysctl_unregister, 171 }, 172 { 173 .init = xe_pm_module_init, 174 }, 175 }; 176 177 static int __init xe_call_init_func(const struct init_funcs *func) 178 { 179 if (func->init) 180 return func->init(); 181 return 0; 182 } 183 184 static void xe_call_exit_func(const struct init_funcs *func) 185 { 186 if (func->exit) 187 func->exit(); 188 } 189 190 static int __init xe_init(void) 191 { 192 int err, i; 193 194 for (i = 0; i < ARRAY_SIZE(init_funcs); i++) { 195 err = xe_call_init_func(init_funcs + i); 196 if (err) { 197 pr_info("%s: module_init aborted at %ps %pe\n", 198 DRIVER_NAME, init_funcs[i].init, ERR_PTR(err)); 199 while (i--) 200 xe_call_exit_func(init_funcs + i); 201 return err; 202 } 203 } 204 205 return 0; 206 } 207 208 static void __exit xe_exit(void) 209 { 210 int i; 211 212 for (i = ARRAY_SIZE(init_funcs) - 1; i >= 0; i--) 213 xe_call_exit_func(init_funcs + i); 214 } 215 216 module_init(xe_init); 217 module_exit(xe_exit); 218 219 MODULE_AUTHOR("Intel Corporation"); 220 221 MODULE_DESCRIPTION(DRIVER_DESC); 222 MODULE_LICENSE("GPL and additional rights"); 223