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