blob: f6bcd2f89257a147f7c042d9d5f7b0e987cfe968 [file] [log] [blame]
Daniel Vetter708b7df2021-07-27 14:10:37 +02001/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright © 2021 Intel Corporation
5 */
6
Javier Martinez Canillas6a2d2dd2021-11-12 14:32:27 +01007#include <drm/drm_drv.h>
Daniel Vetter708b7df2021-07-27 14:10:37 +02008
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
21static int i915_check_nomodeset(void)
22{
23 bool use_kms = true;
24
25 /*
26 * Enable KMS by default, unless explicitly overriden by
Javier Martinez Canillas565edee2021-11-03 13:28:05 +010027 * either the i915.modeset parameter or by the
28 * nomodeset boot option.
Daniel Vetter708b7df2021-07-27 14:10:37 +020029 */
30
31 if (i915_modparams.modeset == 0)
32 use_kms = false;
33
Javier Martinez Canillas6a2d2dd2021-11-12 14:32:27 +010034 if (drm_firmware_drivers_only() && i915_modparams.modeset == -1)
Daniel Vetter708b7df2021-07-27 14:10:37 +020035 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
46static const struct {
47 int (*init)(void);
48 void (*exit)(void);
49} init_funcs[] = {
Kees Cook90fd2192021-08-17 16:33:57 -070050 { .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 },
Jani Nikulaf3ede202021-08-25 18:06:23 +030070 { .init = i915_pci_register_driver,
71 .exit = i915_pci_unregister_driver },
Kees Cook90fd2192021-08-17 16:33:57 -070072 { .init = i915_perf_sysctl_register,
73 .exit = i915_perf_sysctl_unregister },
Daniel Vetter708b7df2021-07-27 14:10:37 +020074};
75static int init_progress;
76
77static 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
106static 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
117module_init(i915_init);
118module_exit(i915_exit);
119
120MODULE_AUTHOR("Tungsten Graphics, Inc.");
121MODULE_AUTHOR("Intel Corporation");
122
123MODULE_DESCRIPTION(DRIVER_DESC);
124MODULE_LICENSE("GPL and additional rights");