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