xref: /linux/drivers/gpu/drm/xe/xe_module.c (revision 40a684f91d267164f9adf0d35b572b4cad0b8d3c)
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 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 
46 module_param_named(vram_bar_size, xe_modparam.force_vram_bar_size, int, 0600);
47 MODULE_PARM_DESC(vram_bar_size, "Set the vram bar size in MiB (<0=disable-resize, 0=max-needed-size, >0=force-size "
48 		 "[default=" __stringify(XE_DEFAULT_VRAM_BAR_SIZE) "])");
49 
50 module_param_named(guc_log_level, xe_modparam.guc_log_level, int, 0600);
51 MODULE_PARM_DESC(guc_log_level, "GuC firmware logging level (0=disable, 1=normal, 2..5=verbose-levels "
52 		 "[default=" __stringify(XE_DEFAULT_GUC_LOG_LEVEL) "])");
53 
54 module_param_named_unsafe(guc_firmware_path, xe_modparam.guc_firmware_path, charp, 0400);
55 MODULE_PARM_DESC(guc_firmware_path,
56 		 "GuC firmware path to use instead of the default one");
57 
58 module_param_named_unsafe(huc_firmware_path, xe_modparam.huc_firmware_path, charp, 0400);
59 MODULE_PARM_DESC(huc_firmware_path,
60 		 "HuC firmware path to use instead of the default one - empty string disables");
61 
62 module_param_named_unsafe(gsc_firmware_path, xe_modparam.gsc_firmware_path, charp, 0400);
63 MODULE_PARM_DESC(gsc_firmware_path,
64 		 "GSC firmware path to use instead of the default one - empty string disables");
65 
66 module_param_named_unsafe(force_probe, xe_modparam.force_probe, charp, 0400);
67 MODULE_PARM_DESC(force_probe,
68 		 "Force probe options for specified devices. See CONFIG_DRM_XE_FORCE_PROBE for details "
69 		 "[default=" XE_DEFAULT_FORCE_PROBE "])");
70 
71 #ifdef CONFIG_PCI_IOV
72 module_param_named(max_vfs, xe_modparam.max_vfs, uint, 0400);
73 MODULE_PARM_DESC(max_vfs,
74 		 "Limit number of Virtual Functions (VFs) that could be managed. "
75 		 "(0=no VFs; N=allow up to N VFs "
76 		 "[default=" XE_DEFAULT_MAX_VFS_STR "])");
77 #endif
78 
79 module_param_named_unsafe(wedged_mode, xe_modparam.wedged_mode, uint, 0600);
80 MODULE_PARM_DESC(wedged_mode,
81 		 "Module's default policy for the wedged mode (0=never, 1=upon-critical-error, 2=upon-any-hang-no-reset "
82 		 "[default=" XE_DEFAULT_WEDGED_MODE_STR "])");
83 
84 static int xe_check_nomodeset(void)
85 {
86 	if (drm_firmware_drivers_only())
87 		return -ENODEV;
88 
89 	return 0;
90 }
91 
92 struct init_funcs {
93 	int (*init)(void);
94 	void (*exit)(void);
95 };
96 
97 static const struct init_funcs init_funcs[] = {
98 	{
99 		.init = xe_check_nomodeset,
100 	},
101 	{
102 		.init = xe_configfs_init,
103 		.exit = xe_configfs_exit,
104 	},
105 	{
106 		.init = xe_hw_fence_module_init,
107 		.exit = xe_hw_fence_module_exit,
108 	},
109 	{
110 		.init = xe_sched_job_module_init,
111 		.exit = xe_sched_job_module_exit,
112 	},
113 	{
114 		.init = xe_register_pci_driver,
115 		.exit = xe_unregister_pci_driver,
116 	},
117 	{
118 		.init = xe_observation_sysctl_register,
119 		.exit = xe_observation_sysctl_unregister,
120 	},
121 	{
122 		.init = xe_pm_module_init,
123 	},
124 };
125 
126 static int __init xe_call_init_func(const struct init_funcs *func)
127 {
128 	if (func->init)
129 		return func->init();
130 	return 0;
131 }
132 
133 static void xe_call_exit_func(const struct init_funcs *func)
134 {
135 	if (func->exit)
136 		func->exit();
137 }
138 
139 static int __init xe_init(void)
140 {
141 	int err, i;
142 
143 	for (i = 0; i < ARRAY_SIZE(init_funcs); i++) {
144 		err = xe_call_init_func(init_funcs + i);
145 		if (err) {
146 			pr_info("%s: module_init aborted at %ps %pe\n",
147 				DRIVER_NAME, init_funcs[i].init, ERR_PTR(err));
148 			while (i--)
149 				xe_call_exit_func(init_funcs + i);
150 			return err;
151 		}
152 	}
153 
154 	return 0;
155 }
156 
157 static void __exit xe_exit(void)
158 {
159 	int i;
160 
161 	for (i = ARRAY_SIZE(init_funcs) - 1; i >= 0; i--)
162 		xe_call_exit_func(init_funcs + i);
163 }
164 
165 module_init(xe_init);
166 module_exit(xe_exit);
167 
168 MODULE_AUTHOR("Intel Corporation");
169 
170 MODULE_DESCRIPTION(DRIVER_DESC);
171 MODULE_LICENSE("GPL and additional rights");
172