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