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
22static 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 use_kms = false;
34
35 if (drm_firmware_drivers_only() && i915_modparams.modeset == -1)
36 use_kms = false;
37
38 if (!use_kms) {
39 /* Silently fail loading to not upset userspace. */
40 DRM_DEBUG_DRIVER("KMS disabled.\n");
41 return 1;
42 }
43
44 return 0;
45}
46
47static const struct {
48 int (*init)(void);
49 void (*exit)(void);
50} init_funcs[] = {
51 { .init = i915_check_nomodeset },
52 { .init = i915_active_module_init,
53 .exit = i915_active_module_exit },
54 { .init = i915_context_module_init,
55 .exit = i915_context_module_exit },
56 { .init = i915_gem_context_module_init,
57 .exit = i915_gem_context_module_exit },
58 { .init = i915_objects_module_init,
59 .exit = i915_objects_module_exit },
60 { .init = i915_request_module_init,
61 .exit = i915_request_module_exit },
62 { .init = i915_scheduler_module_init,
63 .exit = i915_scheduler_module_exit },
64 { .init = i915_vma_module_init,
65 .exit = i915_vma_module_exit },
66 { .init = i915_vma_resource_module_init,
67 .exit = i915_vma_resource_module_exit },
68 { .init = i915_mock_selftests },
69 { .init = i915_pmu_init,
70 .exit = i915_pmu_exit },
71 { .init = i915_pci_register_driver,
72 .exit = i915_pci_unregister_driver },
73 { .init = i915_perf_sysctl_register,
74 .exit = i915_perf_sysctl_unregister },
75};
76static int init_progress;
77
78static int __init i915_init(void)
79{
80 int err, i;
81
82 for (i = 0; i < ARRAY_SIZE(init_funcs); i++) {
83 err = init_funcs[i].init();
84 if (err < 0) {
85 while (i--) {
86 if (init_funcs[i].exit)
87 init_funcs[i].exit();
88 }
89 return err;
90 } else if (err > 0) {
91 /*
92 * Early-exit success is reserved for things which
93 * don't have an exit() function because we have no
94 * idea how far they got or how to partially tear
95 * them down.
96 */
97 WARN_ON(init_funcs[i].exit);
98 break;
99 }
100 }
101
102 init_progress = i;
103
104 return 0;
105}
106
107static void __exit i915_exit(void)
108{
109 int i;
110
111 for (i = init_progress - 1; i >= 0; i--) {
112 GEM_BUG_ON(i >= ARRAY_SIZE(init_funcs));
113 if (init_funcs[i].exit)
114 init_funcs[i].exit();
115 }
116}
117
118module_init(i915_init);
119module_exit(i915_exit);
120
121MODULE_AUTHOR("Tungsten Graphics, Inc.");
122MODULE_AUTHOR("Intel Corporation");
123
124MODULE_DESCRIPTION(DRIVER_DESC);
125MODULE_LICENSE("GPL and additional rights");
126

source code of linux/drivers/gpu/drm/i915/i915_module.c