xref: /linux/drivers/gpu/drm/xe/xe_module.c (revision f86ad0ed620cb3c91ec7d5468e93ac68d727539d)
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 struct xe_modparam xe_modparam = {
28 	.probe_display = true,
29 	.guc_log_level = DEFAULT_GUC_LOG_LEVEL,
30 	.force_probe = CONFIG_DRM_XE_FORCE_PROBE,
31 	.wedged_mode = 1,
32 	.svm_notifier_size = 512,
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 
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 (default: true)");
44 
45 module_param_named(vram_bar_size, xe_modparam.force_vram_bar_size, int, 0600);
46 MODULE_PARM_DESC(vram_bar_size, "Set the vram bar size (in MiB) - <0=disable-resize, 0=max-needed-size[default], >0=force-size");
47 
48 module_param_named(guc_log_level, xe_modparam.guc_log_level, int, 0600);
49 MODULE_PARM_DESC(guc_log_level, "GuC firmware logging level (0=disable, 1=normal, 2..5=verbose-levels "
50 		 "[default=" __stringify(DEFAULT_GUC_LOG_LEVEL) "])");
51 
52 module_param_named_unsafe(guc_firmware_path, xe_modparam.guc_firmware_path, charp, 0400);
53 MODULE_PARM_DESC(guc_firmware_path,
54 		 "GuC firmware path to use instead of the default one");
55 
56 module_param_named_unsafe(huc_firmware_path, xe_modparam.huc_firmware_path, charp, 0400);
57 MODULE_PARM_DESC(huc_firmware_path,
58 		 "HuC firmware path to use instead of the default one - empty string disables");
59 
60 module_param_named_unsafe(gsc_firmware_path, xe_modparam.gsc_firmware_path, charp, 0400);
61 MODULE_PARM_DESC(gsc_firmware_path,
62 		 "GSC firmware path to use instead of the default one - empty string disables");
63 
64 module_param_named_unsafe(force_probe, xe_modparam.force_probe, charp, 0400);
65 MODULE_PARM_DESC(force_probe,
66 		 "Force probe options for specified devices. See CONFIG_DRM_XE_FORCE_PROBE for details.");
67 
68 #ifdef CONFIG_PCI_IOV
69 module_param_named(max_vfs, xe_modparam.max_vfs, uint, 0400);
70 MODULE_PARM_DESC(max_vfs,
71 		 "Limit number of Virtual Functions (VFs) that could be managed. "
72 		 "(0 = no VFs [default]; N = allow up to N VFs)");
73 #endif
74 
75 module_param_named_unsafe(wedged_mode, xe_modparam.wedged_mode, int, 0600);
76 MODULE_PARM_DESC(wedged_mode,
77 		 "Module's default policy for the wedged mode - 0=never, 1=upon-critical-errors[default], 2=upon-any-hang");
78 
79 static int xe_check_nomodeset(void)
80 {
81 	if (drm_firmware_drivers_only())
82 		return -ENODEV;
83 
84 	return 0;
85 }
86 
87 struct init_funcs {
88 	int (*init)(void);
89 	void (*exit)(void);
90 };
91 
92 static const struct init_funcs init_funcs[] = {
93 	{
94 		.init = xe_check_nomodeset,
95 	},
96 	{
97 		.init = xe_configfs_init,
98 		.exit = xe_configfs_exit,
99 	},
100 	{
101 		.init = xe_hw_fence_module_init,
102 		.exit = xe_hw_fence_module_exit,
103 	},
104 	{
105 		.init = xe_sched_job_module_init,
106 		.exit = xe_sched_job_module_exit,
107 	},
108 	{
109 		.init = xe_register_pci_driver,
110 		.exit = xe_unregister_pci_driver,
111 	},
112 	{
113 		.init = xe_observation_sysctl_register,
114 		.exit = xe_observation_sysctl_unregister,
115 	},
116 	{
117 		.init = xe_pm_module_init,
118 	},
119 };
120 
121 static int __init xe_call_init_func(unsigned int i)
122 {
123 	if (WARN_ON(i >= ARRAY_SIZE(init_funcs)))
124 		return 0;
125 	if (!init_funcs[i].init)
126 		return 0;
127 
128 	return init_funcs[i].init();
129 }
130 
131 static void xe_call_exit_func(unsigned int i)
132 {
133 	if (WARN_ON(i >= ARRAY_SIZE(init_funcs)))
134 		return;
135 	if (!init_funcs[i].exit)
136 		return;
137 
138 	init_funcs[i].exit();
139 }
140 
141 static int __init xe_init(void)
142 {
143 	int err, i;
144 
145 	for (i = 0; i < ARRAY_SIZE(init_funcs); i++) {
146 		err = xe_call_init_func(i);
147 		if (err) {
148 			while (i--)
149 				xe_call_exit_func(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(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