3 * Copyright (c) 2011-2015, ARM Limited. All rights reserved.
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
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.
15 #include "BdsInternal.h"
18 ShutdownUefiBootServices (
24 EFI_MEMORY_DESCRIPTOR
*MemoryMap
;
27 UINT32 DescriptorVersion
;
35 Status
= gBS
->GetMemoryMap (
42 if (Status
== EFI_BUFFER_TOO_SMALL
) {
44 Pages
= EFI_SIZE_TO_PAGES (MemoryMapSize
) + 1;
45 MemoryMap
= AllocatePages (Pages
);
48 // Get System MemoryMap
50 Status
= gBS
->GetMemoryMap (
59 // Don't do anything between the GetMemoryMap() and ExitBootServices()
60 if (!EFI_ERROR(Status
)) {
61 Status
= gBS
->ExitBootServices (gImageHandle
, MapKey
);
62 if (EFI_ERROR(Status
)) {
63 FreePages (MemoryMap
, Pages
);
68 } while (EFI_ERROR(Status
));
74 Connect all DXE drivers
76 @retval EFI_SUCCESS All drivers have been connected
77 @retval EFI_NOT_FOUND No handles match the search.
78 @retval EFI_OUT_OF_RESOURCES There is not resource pool memory to store the matching results.
82 BdsConnectAllDrivers (
86 UINTN HandleCount
, Index
;
87 EFI_HANDLE
*HandleBuffer
;
91 // Locate all the driver handles
92 Status
= gBS
->LocateHandleBuffer (
99 if (EFI_ERROR (Status
)) {
103 // Connect every handles
104 for (Index
= 0; Index
< HandleCount
; Index
++) {
105 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
108 if (HandleBuffer
!= NULL
) {
109 FreePool (HandleBuffer
);
112 // Check if new handles have been created after the start of the previous handles
113 Status
= gDS
->Dispatch ();
114 } while (!EFI_ERROR(Status
));
120 GetGlobalEnvironmentVariable (
121 IN CONST CHAR16
* VariableName
,
122 IN VOID
* DefaultValue
,
127 return GetEnvironmentVariable (VariableName
, &gEfiGlobalVariableGuid
,
128 DefaultValue
, Size
, Value
);
132 GetEnvironmentVariable (
133 IN CONST CHAR16
* VariableName
,
134 IN EFI_GUID
* VendorGuid
,
135 IN VOID
* DefaultValue
,
143 // Try to get the variable size.
146 Status
= gRT
->GetVariable ((CHAR16
*) VariableName
, VendorGuid
, NULL
, &VariableSize
, *Value
);
147 if (Status
== EFI_NOT_FOUND
) {
148 if ((DefaultValue
!= NULL
) && (Size
!= NULL
) && (*Size
!= 0)) {
149 // If the environment variable does not exist yet then set it with the default value
150 Status
= gRT
->SetVariable (
151 (CHAR16
*)VariableName
,
153 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
157 *Value
= AllocateCopyPool (*Size
, DefaultValue
);
159 return EFI_NOT_FOUND
;
161 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
162 // Get the environment variable value
163 *Value
= AllocatePool (VariableSize
);
164 if (*Value
== NULL
) {
165 return EFI_OUT_OF_RESOURCES
;
168 Status
= gRT
->GetVariable ((CHAR16
*)VariableName
, VendorGuid
, NULL
, &VariableSize
, *Value
);
169 if (EFI_ERROR (Status
)) {
171 return EFI_INVALID_PARAMETER
;
175 *Size
= VariableSize
;
178 *Value
= AllocateCopyPool (*Size
, DefaultValue
);