xref: /linux/drivers/gpu/drm/i915/i915_module.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2021 Intel Corporation
5  */
6 
7 #include <drm/drm_drv.h>
8 
9 #include "gem/i915_gem_context.h"
10 #include "gem/i915_gem_object.h"
11 #include "i915_active.h"
12 #include "i915_driver.h"
13 #include "i915_params.h"
14 #include "i915_pci.h"
15 #include "i915_perf.h"
16 #include "i915_request.h"
17 #include "i915_scheduler.h"
18 #include "i915_selftest.h"
19 #include "i915_vma.h"
20 #include "i915_vma_resource.h"
21 
i915_check_nomodeset(void)22 static int i915_check_nomodeset(void)
23 {
24 	bool use_kms = true;
25 
26 	/*
27 	 * Enable KMS by default, unless explicitly overriden by
28 	 * either the i915.modeset parameter or by the
29 	 * nomodeset boot option.
30 	 */
31 
32 	if (i915_modparams.modeset == 0)
33 		pr_warn("i915.modeset=0 is deprecated. Please use the 'nomodeset' kernel parameter instead.\n");
34 	else if (i915_modparams.modeset != -1)
35 		pr_warn("i915.modeset=%d is deprecated. Please remove it and the 'nomodeset' kernel parameter instead.\n",
36 			i915_modparams.modeset);
37 
38 	if (i915_modparams.modeset == 0)
39 		use_kms = false;
40 
41 	if (drm_firmware_drivers_only() && i915_modparams.modeset == -1)
42 		use_kms = false;
43 
44 	if (!use_kms) {
45 		DRM_DEBUG_DRIVER("KMS disabled.\n");
46 		return -ENODEV;
47 	}
48 
49 	return 0;
50 }
51 
52 static const struct {
53    int (*init)(void);
54    void (*exit)(void);
55 } init_funcs[] = {
56 	{ .init = i915_check_nomodeset },
57 	{ .init = i915_active_module_init,
58 	  .exit = i915_active_module_exit },
59 	{ .init = i915_context_module_init,
60 	  .exit = i915_context_module_exit },
61 	{ .init = i915_gem_context_module_init,
62 	  .exit = i915_gem_context_module_exit },
63 	{ .init = i915_objects_module_init,
64 	  .exit = i915_objects_module_exit },
65 	{ .init = i915_request_module_init,
66 	  .exit = i915_request_module_exit },
67 	{ .init = i915_scheduler_module_init,
68 	  .exit = i915_scheduler_module_exit },
69 	{ .init = i915_vma_module_init,
70 	  .exit = i915_vma_module_exit },
71 	{ .init = i915_vma_resource_module_init,
72 	  .exit = i915_vma_resource_module_exit },
73 	{ .init = i915_mock_selftests },
74 	{ .init = i915_pmu_init,
75 	  .exit = i915_pmu_exit },
76 	{ .init = i915_pci_register_driver,
77 	  .exit = i915_pci_unregister_driver },
78 	{ .init = i915_perf_sysctl_register,
79 	  .exit = i915_perf_sysctl_unregister },
80 };
81 static int init_progress;
82 
i915_init(void)83 static int __init i915_init(void)
84 {
85 	int err, i;
86 
87 	for (i = 0; i < ARRAY_SIZE(init_funcs); i++) {
88 		err = init_funcs[i].init();
89 		if (err < 0) {
90 			while (i--) {
91 				if (init_funcs[i].exit)
92 					init_funcs[i].exit();
93 			}
94 			return err;
95 		} else if (err > 0) {
96 			/*
97 			 * Early-exit success is reserved for things which
98 			 * don't have an exit() function because we have no
99 			 * idea how far they got or how to partially tear
100 			 * them down.
101 			 */
102 			WARN_ON(init_funcs[i].exit);
103 			break;
104 		}
105 	}
106 
107 	init_progress = i;
108 
109 	return 0;
110 }
111 
i915_exit(void)112 static void __exit i915_exit(void)
113 {
114 	int i;
115 
116 	for (i = init_progress - 1; i >= 0; i--) {
117 		GEM_BUG_ON(i >= ARRAY_SIZE(init_funcs));
118 		if (init_funcs[i].exit)
119 			init_funcs[i].exit();
120 	}
121 }
122 
123 module_init(i915_init);
124 module_exit(i915_exit);
125 
126 MODULE_AUTHOR("Tungsten Graphics, Inc.");
127 MODULE_AUTHOR("Intel Corporation");
128 
129 MODULE_DESCRIPTION(DRIVER_DESC);
130 MODULE_LICENSE("GPL and additional rights");
131