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