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