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