1 /** @file
2 The module entry point for SecureBoot configuration module.
3
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "SecureBootConfigImpl.h"
16
17 /**
18 The entry point for SecureBoot configuration driver.
19
20 @param[in] ImageHandle The image handle of the driver.
21 @param[in] SystemTable The system table.
22
23 @retval EFI_ALREADY_STARTED The driver already exists in system.
24 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of resources.
25 @retval EFI_SUCCES All the related protocols are installed on the driver.
26 @retval Others Fail to get the SecureBootEnable variable.
27
28 **/
29 EFI_STATUS
30 EFIAPI
SecureBootConfigDriverEntryPoint(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)31 SecureBootConfigDriverEntryPoint (
32 IN EFI_HANDLE ImageHandle,
33 IN EFI_SYSTEM_TABLE *SystemTable
34 )
35 {
36 EFI_STATUS Status;
37 SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData;
38
39 //
40 // If already started, return.
41 //
42 Status = gBS->OpenProtocol (
43 ImageHandle,
44 &gEfiCallerIdGuid,
45 NULL,
46 ImageHandle,
47 ImageHandle,
48 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
49 );
50 if (!EFI_ERROR (Status)) {
51 return EFI_ALREADY_STARTED;
52 }
53
54 //
55 // Create a private data structure.
56 //
57 PrivateData = AllocateCopyPool (sizeof (SECUREBOOT_CONFIG_PRIVATE_DATA), &mSecureBootConfigPrivateDateTemplate);
58 if (PrivateData == NULL) {
59 return EFI_OUT_OF_RESOURCES;
60 }
61
62 //
63 // Install SecureBoot configuration form
64 //
65 Status = InstallSecureBootConfigForm (PrivateData);
66 if (EFI_ERROR (Status)) {
67 goto ErrorExit;
68 }
69
70 //
71 // Install private GUID.
72 //
73 Status = gBS->InstallMultipleProtocolInterfaces (
74 &ImageHandle,
75 &gEfiCallerIdGuid,
76 PrivateData,
77 NULL
78 );
79
80 if (EFI_ERROR (Status)) {
81 goto ErrorExit;
82 }
83
84 return EFI_SUCCESS;
85
86 ErrorExit:
87 if (PrivateData != NULL) {
88 UninstallSecureBootConfigForm (PrivateData);
89 }
90
91 return Status;
92 }
93
94 /**
95 Unload the SecureBoot configuration form.
96
97 @param[in] ImageHandle The driver's image handle.
98
99 @retval EFI_SUCCESS The SecureBoot configuration form is unloaded.
100 @retval Others Failed to unload the form.
101
102 **/
103 EFI_STATUS
104 EFIAPI
SecureBootConfigDriverUnload(IN EFI_HANDLE ImageHandle)105 SecureBootConfigDriverUnload (
106 IN EFI_HANDLE ImageHandle
107 )
108 {
109 EFI_STATUS Status;
110 SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData;
111
112 Status = gBS->HandleProtocol (
113 ImageHandle,
114 &gEfiCallerIdGuid,
115 (VOID **) &PrivateData
116 );
117 if (EFI_ERROR (Status)) {
118 return Status;
119 }
120
121 ASSERT (PrivateData->Signature == SECUREBOOT_CONFIG_PRIVATE_DATA_SIGNATURE);
122
123 gBS->UninstallMultipleProtocolInterfaces (
124 &ImageHandle,
125 &gEfiCallerIdGuid,
126 PrivateData,
127 NULL
128 );
129
130 UninstallSecureBootConfigForm (PrivateData);
131
132 return EFI_SUCCESS;
133 }
134