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