]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDriver.c
6c0294151e6ca3cf7bb021a4cdd6b7808bf9c615
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / SecureBootConfigDxe / SecureBootConfigDriver.c
1 /** @file
2 The module entry point for SecureBoot configuration module.
3
4 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "SecureBootConfigImpl.h"
10
11 /**
12 The entry point for SecureBoot configuration driver.
13
14 @param[in] ImageHandle The image handle of the driver.
15 @param[in] SystemTable The system table.
16
17 @retval EFI_ALREADY_STARTED The driver already exists in system.
18 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of resources.
19 @retval EFI_SUCCES All the related protocols are installed on the driver.
20 @retval Others Fail to get the SecureBootEnable variable.
21
22 **/
23 EFI_STATUS
24 EFIAPI
25 SecureBootConfigDriverEntryPoint (
26 IN EFI_HANDLE ImageHandle,
27 IN EFI_SYSTEM_TABLE *SystemTable
28 )
29 {
30 EFI_STATUS Status;
31 SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData;
32
33 //
34 // If already started, return.
35 //
36 Status = gBS->OpenProtocol (
37 ImageHandle,
38 &gEfiCallerIdGuid,
39 NULL,
40 ImageHandle,
41 ImageHandle,
42 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
43 );
44 if (!EFI_ERROR (Status)) {
45 return EFI_ALREADY_STARTED;
46 }
47
48 //
49 // Create a private data structure.
50 //
51 PrivateData = AllocateCopyPool (sizeof (SECUREBOOT_CONFIG_PRIVATE_DATA), &mSecureBootConfigPrivateDateTemplate);
52 if (PrivateData == NULL) {
53 return EFI_OUT_OF_RESOURCES;
54 }
55
56 //
57 // Install SecureBoot configuration form
58 //
59 Status = InstallSecureBootConfigForm (PrivateData);
60 if (EFI_ERROR (Status)) {
61 goto ErrorExit;
62 }
63
64 //
65 // Install private GUID.
66 //
67 Status = gBS->InstallMultipleProtocolInterfaces (
68 &ImageHandle,
69 &gEfiCallerIdGuid,
70 PrivateData,
71 NULL
72 );
73
74 if (EFI_ERROR (Status)) {
75 goto ErrorExit;
76 }
77
78 return EFI_SUCCESS;
79
80 ErrorExit:
81 if (PrivateData != NULL) {
82 UninstallSecureBootConfigForm (PrivateData);
83 }
84
85 return Status;
86 }
87
88 /**
89 Unload the SecureBoot configuration form.
90
91 @param[in] ImageHandle The driver's image handle.
92
93 @retval EFI_SUCCESS The SecureBoot configuration form is unloaded.
94 @retval Others Failed to unload the form.
95
96 **/
97 EFI_STATUS
98 EFIAPI
99 SecureBootConfigDriverUnload (
100 IN EFI_HANDLE ImageHandle
101 )
102 {
103 EFI_STATUS Status;
104 SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData;
105
106 Status = gBS->HandleProtocol (
107 ImageHandle,
108 &gEfiCallerIdGuid,
109 (VOID **) &PrivateData
110 );
111 if (EFI_ERROR (Status)) {
112 return Status;
113 }
114
115 ASSERT (PrivateData->Signature == SECUREBOOT_CONFIG_PRIVATE_DATA_SIGNATURE);
116
117 gBS->UninstallMultipleProtocolInterfaces (
118 ImageHandle,
119 &gEfiCallerIdGuid,
120 PrivateData,
121 NULL
122 );
123
124 UninstallSecureBootConfigForm (PrivateData);
125
126 return EFI_SUCCESS;
127 }