Daniel Vetter | 708b7df | 2021-07-27 14:10:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright © 2021 Intel Corporation |
| 5 | */ |
| 6 | |
Javier Martinez Canillas | 6a2d2dd | 2021-11-12 14:32:27 +0100 | [diff] [blame] | 7 | #include <drm/drm_drv.h> |
Daniel Vetter | 708b7df | 2021-07-27 14:10:37 +0200 | [diff] [blame] | 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 |
Javier Martinez Canillas | 565edee | 2021-11-03 13:28:05 +0100 | [diff] [blame] | 27 | * either the i915.modeset parameter or by the |
| 28 | * nomodeset boot option. |
Daniel Vetter | 708b7df | 2021-07-27 14:10:37 +0200 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | if (i915_modparams.modeset == 0) |
| 32 | use_kms = false; |
| 33 | |
Javier Martinez Canillas | 6a2d2dd | 2021-11-12 14:32:27 +0100 | [diff] [blame] | 34 | if (drm_firmware_drivers_only() && i915_modparams.modeset == -1) |
Daniel Vetter | 708b7df | 2021-07-27 14:10:37 +0200 | [diff] [blame] | 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[] = { |
Kees Cook | 90fd219 | 2021-08-17 16:33:57 -0700 | [diff] [blame] | 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 }, |
Jani Nikula | f3ede20 | 2021-08-25 18:06:23 +0300 | [diff] [blame] | 70 | { .init = i915_pci_register_driver, |
| 71 | .exit = i915_pci_unregister_driver }, |
Kees Cook | 90fd219 | 2021-08-17 16:33:57 -0700 | [diff] [blame] | 72 | { .init = i915_perf_sysctl_register, |
| 73 | .exit = i915_perf_sysctl_unregister }, |
Daniel Vetter | 708b7df | 2021-07-27 14:10:37 +0200 | [diff] [blame] | 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"); |