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