38 TempNewDevicePath =
NULL;
40 if ((Multi ==
NULL) || (Single ==
NULL)) {
46 InstanceSize -= END_DEVICE_PATH_LENGTH;
48 while (Instance !=
NULL) {
49 if (
CompareMem (Instance, Single,
MIN (SingleDpSize, InstanceSize)) != 0) {
53 TempNewDevicePath = NewDevicePath;
55 if (TempNewDevicePath !=
NULL) {
62 InstanceSize -= END_DEVICE_PATH_LENGTH;
91 if ((Multi ==
NULL) || (Single ==
NULL)) {
101 while (DevicePathInst !=
NULL) {
106 if (
CompareMem (Single, DevicePathInst, Size) == 0) {
143 BOOLEAN MemoryTypeInformationModified;
144 BOOLEAN MemoryTypeInformationVariableExists;
147 MemoryTypeInformationModified =
FALSE;
148 MemoryTypeInformationVariableExists =
FALSE;
154 if (BootMode == BOOT_IN_RECOVERY_MODE) {
163 if (BootMode != BOOT_WITH_DEFAULT_SETTINGS) {
165 Status =
gRT->GetVariable (
166 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
167 &gEfiMemoryTypeInformationGuid,
172 if (Status == EFI_BUFFER_TOO_SMALL) {
173 MemoryTypeInformationVariableExists =
TRUE;
182 &gEfiMemoryTypeInformationGuid,
183 (VOID **)&CurrentMemoryTypeInformation
185 if (EFI_ERROR (Status) || (CurrentMemoryTypeInformation ==
NULL)) {
195 if (GuidHob ==
NULL) {
202 VariableSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
203 PreviousMemoryTypeInformation =
AllocateCopyPool (VariableSize, GET_GUID_HOB_DATA (GuidHob));
204 if (PreviousMemoryTypeInformation ==
NULL) {
211 DEBUG ((DEBUG_INFO,
"Memory Previous Current Next \n"));
212 DEBUG ((DEBUG_INFO,
" Type Pages Pages Pages \n"));
213 DEBUG ((DEBUG_INFO,
"====== ======== ======== ========\n"));
215 for (Index = 0; PreviousMemoryTypeInformation[Index].
Type != EfiMaxMemoryType; Index++) {
216 for (Index1 = 0; CurrentMemoryTypeInformation[Index1].
Type != EfiMaxMemoryType; Index1++) {
217 if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) {
222 if (CurrentMemoryTypeInformation[Index1].Type == EfiMaxMemoryType) {
230 Previous = PreviousMemoryTypeInformation[Index].
NumberOfPages;
231 Current = CurrentMemoryTypeInformation[Index1].
NumberOfPages;
240 if ((Current + (Current >> 1)) < Previous) {
241 if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {
242 Next = Current + (Current >> 2);
244 }
else if (Current > Previous) {
245 Next = Current + (Current >> 2);
248 if ((Next > 0) && (Next < 4)) {
252 if (Next != Previous) {
254 MemoryTypeInformationModified =
TRUE;
257 DEBUG ((DEBUG_INFO,
" %02x %08x %08x %08x\n", PreviousMemoryTypeInformation[Index].Type, Previous, Current, Next));
264 if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExists) {
266 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
267 &gEfiMemoryTypeInformationGuid,
270 PreviousMemoryTypeInformation
273 if (!EFI_ERROR (Status)) {
279 if (MemoryTypeInformationModified) {
280 DEBUG ((DEBUG_INFO,
"Memory Type Information settings change.\n"));
281 if (Boot &&
PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {
282 DEBUG ((DEBUG_INFO,
"...Warm Reset!!!\n"));
287 DEBUG ((DEBUG_ERROR,
"Memory Type Information settings cannot be saved. OS S4 may fail!\n"));
291 FreePool (PreviousMemoryTypeInformation);
329 IN CHAR16 *VariableName,
331 IN UINT32 Attributes,
340 Status =
gRT->SetVariable (
347 if (EFI_ERROR (Status)) {
348 NameSize =
StrSize (VariableName);
350 if (SetVariableStatus !=
NULL) {
351 CopyGuid (&SetVariableStatus->Guid, VendorGuid);
352 SetVariableStatus->NameSize = NameSize;
353 SetVariableStatus->DataSize = DataSize;
354 SetVariableStatus->SetStatus = Status;
355 SetVariableStatus->Attributes = Attributes;
356 CopyMem (SetVariableStatus + 1, VariableName, NameSize);
357 CopyMem (((UINT8 *)(SetVariableStatus + 1)) + NameSize, Data, DataSize);
364 &gEdkiiStatusCodeDataTypeVariableGuid,
389 DEBUG ((DEBUG_INFO,
"%s", Str));
408 if ((Char >= L
'0') && (Char <= L
'9')) {
409 return (Char - L
'0');
412 if ((Char >= L
'A') && (Char <= L
'F')) {
413 return (Char - L
'A' + 0xA);
451 Status =
gBS->LocateHandleBuffer (
453 &gEfiDeferredImageLoadProtocolGuid,
458 if (EFI_ERROR (Status)) {
459 return EFI_NOT_FOUND;
464 for (Index = 0; Index < HandleCount; Index++) {
465 Status =
gBS->HandleProtocol (Handles[Index], &gEfiDeferredImageLoadProtocolGuid, (VOID **)&DeferredImage);
466 if (EFI_ERROR (Status)) {
470 for (ImageIndex = 0; ; ImageIndex++) {
474 Status = DeferredImage->GetImageInfo (
482 if (EFI_ERROR (Status)) {
490 Status =
gBS->LoadImage (
498 if (EFI_ERROR (Status)) {
505 if (Status == EFI_SECURITY_VIOLATION) {
506 gBS->UnloadImage (ImageHandle);
514 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00,
NULL);
520 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000,
NULL);
525 if (Handles !=
NULL) {
529 if (ImageCount == 0) {
530 return EFI_NOT_FOUND;
532 if (LoadCount == 0) {
533 return EFI_ACCESS_DENIED;
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
EFI_BOOT_MODE EFIAPI GetBootModeHob(VOID)
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
EFI_STATUS EFIAPI EfiBootManagerDispatchDeferredImages(VOID)
VOID BmSetMemoryTypeInformationVariable(IN BOOLEAN Boot)
VOID BmPrintDp(EFI_DEVICE_PATH_PROTOCOL *DevicePath)
UINTN BmCharToUint(IN CHAR16 Char)
EFI_STATUS BmSetVariableAndReportStatusCodeOnError(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
EFI_DEVICE_PATH_PROTOCOL * BmDelPartMatchInstance(IN EFI_DEVICE_PATH_PROTOCOL *Multi, IN EFI_DEVICE_PATH_PROTOCOL *Single)
BOOLEAN BmMatchDevicePaths(IN EFI_DEVICE_PATH_PROTOCOL *Multi, IN EFI_DEVICE_PATH_PROTOCOL *Single)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathInstance(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI GetNextDevicePathInstance(IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, OUT UINTN *Size)
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_RUNTIME_SERVICES * gRT
#define DEBUG(Expression)
#define REPORT_STATUS_CODE_EX(Type, Value, Instance, CallerId, ExtendedDataGuid, ExtendedData, ExtendedDataSize)
#define PcdGet32(TokenName)
#define PcdGetBool(TokenName)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
#define EFI_VARIABLE_NON_VOLATILE
UINT32 NumberOfPages
The pages of this type memory.
UINT32 Type
EFI memory type defined in UEFI specification.