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