EFI_STATUS CreateDefaultOpCode ( IN EFI_IFR_TYPE_VALUE *Value, IN UINT8 Type, IN OUT EFI_HII_UPDATE_DATA *Data ) { EFI_IFR_DEFAULT Default; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if ((Value == NULL) || !IsValidValueType (Type)) { return EFI_INVALID_PARAMETER; } if (Data->Offset + sizeof (EFI_IFR_DEFAULT) > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } Default.Header.OpCode = EFI_IFR_DEFAULT_OP; Default.Header.Length = (UINT8) sizeof (EFI_IFR_DEFAULT); Default.Header.Scope = 0; Default.Type = Type; Default.DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD; EfiCopyMem (&Default.Value, Value, sizeof(EFI_IFR_TYPE_VALUE)); LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &Default, sizeof (EFI_IFR_DEFAULT)); Data->Offset += sizeof (EFI_IFR_DEFAULT); return EFI_SUCCESS; }
EFI_STATUS CreateBannerOpCode ( IN EFI_STRING_ID Title, IN UINT16 LineNumber, IN UINT8 Alignment, IN OUT EFI_HII_UPDATE_DATA *Data ) { EFI_IFR_GUID_BANNER Banner; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if (Data->Offset + sizeof (EFI_IFR_GUID_BANNER) > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } Banner.Header.OpCode = EFI_IFR_GUID_OP; Banner.Header.Length = (UINT8) sizeof (EFI_IFR_GUID_BANNER); Banner.Header.Scope = 0; EfiCopyMem (&Banner.Guid, &mIfrVendorGuid, sizeof (EFI_IFR_GUID)); Banner.ExtendOpCode = EFI_IFR_EXTEND_OP_BANNER; Banner.Title = Title; Banner.LineNumber = LineNumber; Banner.Alignment = Alignment; LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &Banner, sizeof (EFI_IFR_GUID_BANNER)); Data->Offset += sizeof (EFI_IFR_GUID_BANNER); return EFI_SUCCESS; }
EFI_STATUS CreateTextOpCode ( IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN EFI_STRING_ID TextTwo, IN OUT EFI_HII_UPDATE_DATA *Data ) { EFI_IFR_TEXT Text; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if (Data->Offset + sizeof (EFI_IFR_TEXT) > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } Text.Header.OpCode = EFI_IFR_TEXT_OP; Text.Header.Length = (UINT8) sizeof (EFI_IFR_TEXT); Text.Header.Scope = 0; Text.Statement.Prompt = Prompt; Text.Statement.Help = Help; Text.TextTwo = TextTwo; LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &Text, sizeof (EFI_IFR_TEXT)); Data->Offset += sizeof (EFI_IFR_TEXT); return EFI_SUCCESS; }
EFI_STATUS CreateSubTitleOpCode ( IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 Flags, IN UINT8 Scope, IN OUT EFI_HII_UPDATE_DATA *Data ) { EFI_IFR_SUBTITLE Subtitle; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if (Data->Offset + sizeof (EFI_IFR_SUBTITLE) > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP; Subtitle.Header.Length = (UINT8) sizeof (EFI_IFR_SUBTITLE); Subtitle.Header.Scope = Scope; Subtitle.Statement.Prompt = Prompt; Subtitle.Statement.Help = Help; Subtitle.Flags = Flags; LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &Subtitle, sizeof (EFI_IFR_SUBTITLE)); Data->Offset += sizeof (EFI_IFR_SUBTITLE); return EFI_SUCCESS; }
EFI_GUID * StslGuidsDuplicate ( IN EFI_GUID *Guids ) { EFI_STATUS Status; UINTN NoGuids; EFI_GUID *Guid; EFI_GUID *Buffer; if (Guids == NULL) { return NULL; } NoGuids = 0; Guid = Guids; while (EfiCompareMem (Guid, &gEfiNullGuid, sizeof(EFI_GUID)) != 0) { NoGuids ++; Guid ++; } Status = gBS->AllocatePool ( EfiBootServicesData, (NoGuids + 1) * sizeof(EFI_GUID), &Buffer ); if (EFI_ERROR (Status)) { return NULL; } EfiCopyMem (Buffer, Guids, (NoGuids + 1) * sizeof(EFI_GUID)); return Buffer; }
EFI_STATUS CreateSubTitleOpCode ( IN STRING_REF StringToken, IN OUT VOID *FormBuffer ) /*++ Routine Description: Create a SubTitle opcode independent of string creation This is used primarily by users who need to create just one particular valid op-code and the string data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label location to pre-defined forms in HII) Arguments: StringToken - StringToken of the subtitle FormBuffer - Output of subtitle as a form Returns: EFI_SUCCESS - Subtitle created to be a form --*/ { EFI_IFR_SUBTITLE Subtitle; Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP; Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE); Subtitle.SubTitle = StringToken; EfiCopyMem (FormBuffer, &Subtitle, sizeof (EFI_IFR_SUBTITLE)); return EFI_SUCCESS; }
VOID UpdateOrderPage ( IN UINT16 UpdatePageId, IN BM_MENU_OPTION *OptionMenu, IN BMM_CALLBACK_DATA *CallbackData ) { BM_MENU_ENTRY *NewMenuEntry; UINT16 Index; IFR_OPTION *IfrOptionList; CallbackData->BmmAskSaveOrNot = TRUE; UpdatePageStart (CallbackData); CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, OptionMenu); EfiZeroMem (CallbackData->BmmFakeNvData.OptionOrder, 100); IfrOptionList = EfiAllocateZeroPool (sizeof (IFR_OPTION) * OptionMenu->MenuNumber); if (NULL == IfrOptionList) { return ; } for (Index = 0; Index < OptionMenu->MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (OptionMenu, Index); IfrOptionList[Index].StringToken = NewMenuEntry->DisplayStringToken; IfrOptionList[Index].Value.u8 = (UINT8) (NewMenuEntry->OptionNumber + 1); IfrOptionList[Index].Flags = 0; CallbackData->BmmFakeNvData.OptionOrder[Index] = IfrOptionList[Index].Value.u8; } if (OptionMenu->MenuNumber > 0) { CreateOrderedListOpCode ( OPTION_ORDER_QUESTION_ID, VARSTORE_ID_BOOT_MAINT, OPTION_ORDER_VAR_OFFSET, STRING_TOKEN (STR_CHANGE_ORDER), STRING_TOKEN (STR_CHANGE_ORDER), 0, 0, EFI_IFR_NUMERIC_SIZE_1, 100, IfrOptionList, OptionMenu->MenuNumber, &gUpdateData ); } SafeFreePool (IfrOptionList); UpdatePageEnd (CallbackData); EfiCopyMem ( CallbackData->BmmOldFakeNVData.OptionOrder, CallbackData->BmmFakeNvData.OptionOrder, 100 ); }
EFI_STATUS CreateOrderedListOpCode ( IN EFI_QUESTION_ID QuestionId, IN EFI_VARSTORE_ID VarStoreId, IN UINT16 VarOffset, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN UINT8 OrderedListFlags, IN UINT8 DataType, IN UINT8 MaxContainers, IN IFR_OPTION *OptionsList, IN UINTN OptionCount, IN OUT EFI_HII_UPDATE_DATA *Data ) { UINTN Length; EFI_IFR_ORDERED_LIST OrderedList; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if (!IsValidQuestionFlags (QuestionFlags) || ((OptionCount != 0) && (OptionsList == NULL))) { return EFI_INVALID_PARAMETER; } if ((OrderedListFlags & (~(EFI_IFR_UNIQUE_SET | EFI_IFR_NO_EMPTY_SET))) != 0) { return EFI_INVALID_PARAMETER; } Length = sizeof (EFI_IFR_ORDERED_LIST) + OptionCount * sizeof (EFI_IFR_ONE_OF_OPTION) + sizeof (EFI_IFR_END); if (Data->Offset + Length > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP; OrderedList.Header.Length = (UINT8) sizeof (EFI_IFR_ORDERED_LIST); OrderedList.Header.Scope = 1; OrderedList.Question.Header.Prompt = Prompt; OrderedList.Question.Header.Help = Help; OrderedList.Question.QuestionId = QuestionId; OrderedList.Question.VarStoreId = VarStoreId; OrderedList.Question.VarStoreInfo.VarOffset = VarOffset; OrderedList.Question.Flags = QuestionFlags; OrderedList.MaxContainers = MaxContainers; OrderedList.Flags = OrderedListFlags; LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &OrderedList, sizeof (EFI_IFR_ORDERED_LIST)); Data->Offset += sizeof (EFI_IFR_ORDERED_LIST); CreateOneOfOptionOpCode (OptionCount, OptionsList, DataType, Data); CreateEndOpCode (Data); return EFI_SUCCESS; }
EFI_STATUS InitWorkSpaceHeader ( IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader ) /*++ Routine Description: Initialize a work space when there is no work space. Arguments: WorkingHeader - Pointer of working block header Returns: EFI_SUCCESS - The function completed successfully EFI_ABORTED - The function could not complete successfully. --*/ { EFI_STATUS Status; ASSERT (WorkingHeader != NULL); // // Here using gEfiSystemNvDataFvGuid as the signature. // EfiCopyMem ( &WorkingHeader->Signature, &gEfiSystemNvDataFvGuid, sizeof (EFI_GUID) ); WorkingHeader->WriteQueueSize = FTW_WORKING_QUEUE_SIZE; // // Crc is calculated with all the fields except Crc and STATE // WorkingHeader->WorkingBlockValid = FTW_ERASE_POLARITY; WorkingHeader->WorkingBlockInvalid = FTW_ERASE_POLARITY; EfiSetMem (&WorkingHeader->Crc, sizeof (UINT32), FTW_ERASED_BYTE); // // Calculate the CRC value // Status = gBS->CalculateCrc32 ( (UINT8 *) WorkingHeader, sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER), &WorkingHeader->Crc ); ASSERT_EFI_ERROR (Status); // // Restore the WorkingBlockValid flag to VALID state // WorkingHeader->WorkingBlockValid = FTW_VALID_STATE; WorkingHeader->WorkingBlockInvalid = FTW_INVALID_STATE; return EFI_SUCCESS; }
STATIC VOID MD5Transform ( IN MD5_CTX *Md5Ctx ) /*++ Routine Description: GC_TODO: Add function description Arguments: Md5Ctx - GC_TODO: add argument description Returns: GC_TODO: add return values --*/ { UINT32 i; UINT32 j; UINT32 S[MD5_HASHSIZE >> 2]; UINT32 *X; UINT32 k; UINT32 t; X = (UINT32 *) Md5Ctx->M; // // Copy MD5 states to S // EfiCopyMem (S, Md5Ctx->States, MD5_HASHSIZE); t = 0; for (i = 0; i < 4; i++) { k = MD5_K[i][0]; for (j = 16; j > 0; j--) { SA += (*MD5_F[i]) (SB, SC, SD) + X[k] + MD5_T[t]; SA = ROTATE_LEFT (SA, MD5_S[i][j & 3]); SA += SB; k += MD5_K[i][1]; k &= 15; t++; } } for (i = 0; i < 4; i++) { Md5Ctx->States[i] += S[i]; } }
EFI_STATUS CreateBannerOpCode ( IN UINT16 Title, IN UINT16 LineNumber, IN UINT8 Alignment, IN OUT VOID *FormBuffer ) /*++ Routine Description: Create a banner opcode. This is primarily used by the FrontPage implementation from BDS. Arguments: Title - Title of the banner LineNumber - LineNumber of the banner Alignment - Alignment of the banner FormBuffer - Output of banner as a form Returns: EFI_SUCCESS - Banner created to be a form. --*/ { EFI_IFR_BANNER Banner; Banner.Header.OpCode = EFI_IFR_BANNER_OP; Banner.Header.Length = sizeof (EFI_IFR_BANNER); EfiCopyMem (&Banner.Title, &Title, sizeof (UINT16)); EfiCopyMem (&Banner.LineNumber, &LineNumber, sizeof (UINT16)); Banner.Alignment = Alignment; EfiCopyMem (FormBuffer, &Banner, sizeof (EFI_IFR_BANNER)); return EFI_SUCCESS; }
EFI_STATUS CreateTextOpCode ( IN STRING_REF StringToken, IN STRING_REF StringTokenTwo, IN STRING_REF StringTokenThree, IN UINT8 Flags, IN UINT16 Key, IN OUT VOID *FormBuffer ) /*++ Routine Description: Create a Text opcode independent of string creation This is used primarily by users who need to create just one particular valid op-code and the string data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label location to pre-defined forms in HII) Arguments: StringToken - First string token of the text StringTokenTwo - Second string token of the text StringTokenThree - Help string token of the text Flags - Flag of the text Key - Key of the text FormBuffer - Output of text as a form Returns: EFI_SUCCESS - Text created to be a form --*/ { EFI_IFR_TEXT Text; Text.Header.OpCode = EFI_IFR_TEXT_OP; Text.Header.Length = sizeof (EFI_IFR_TEXT); Text.Text = StringToken; Text.TextTwo = StringTokenTwo; Text.Help = StringTokenThree; Text.Flags = Flags; Text.Key = Key; EfiCopyMem (FormBuffer, &Text, sizeof (EFI_IFR_TEXT)); return EFI_SUCCESS; }
EFI_STATUS CreateOneOfOpCode ( IN EFI_QUESTION_ID QuestionId, IN EFI_VARSTORE_ID VarStoreId, IN UINT16 VarOffset, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN UINT8 OneOfFlags, IN IFR_OPTION *OptionsList, IN UINTN OptionCount, IN OUT EFI_HII_UPDATE_DATA *Data ) { UINTN Length; EFI_IFR_ONE_OF OneOf; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if (!IsValidNumricFlags (OneOfFlags) || !IsValidQuestionFlags (QuestionFlags) || ((OptionCount != 0) && (OptionsList == NULL))) { return EFI_INVALID_PARAMETER; } Length = sizeof (EFI_IFR_ONE_OF) + OptionCount * sizeof (EFI_IFR_ONE_OF_OPTION) + sizeof (EFI_IFR_END); if (Data->Offset + Length > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP; OneOf.Header.Length = (UINT8) sizeof (EFI_IFR_ONE_OF); OneOf.Header.Scope = 1; OneOf.Question.Header.Prompt = Prompt; OneOf.Question.Header.Help = Help; OneOf.Question.QuestionId = QuestionId; OneOf.Question.VarStoreId = VarStoreId; OneOf.Question.VarStoreInfo.VarOffset = VarOffset; OneOf.Question.Flags = QuestionFlags; OneOf.Flags = OneOfFlags; EfiZeroMem ((VOID *) &OneOf.data, sizeof (MINMAXSTEP_DATA)); LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &OneOf, sizeof (EFI_IFR_ONE_OF)); Data->Offset += sizeof (EFI_IFR_ONE_OF); CreateOneOfOptionOpCode (OptionCount, OptionsList, (UINT8)(OneOfFlags & EFI_IFR_NUMERIC_SIZE), Data); CreateEndOpCode (Data); return EFI_SUCCESS; }
EFI_STATUS CreateGotoOpCode ( IN UINT16 FormId, IN STRING_REF StringToken, IN STRING_REF StringTokenTwo, IN UINT8 Flags, IN UINT16 Key, IN OUT VOID *FormBuffer ) /*++ Routine Description: Create a hyperlink opcode independent of string creation This is used primarily by users who need to create just one particular valid op-code and the string data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label location to pre-defined forms in HII) Arguments: FormId - Form ID of the hyperlink StringToken - Prompt string token of the hyperlink StringTokenTwo - Help string token of the hyperlink Flags - Flags of the hyperlink Key - Key of the hyperlink FormBuffer - Output of hyperlink as a form Returns: EFI_SUCCESS - Hyperlink created to be a form --*/ { EFI_IFR_REF Hyperlink; Hyperlink.Header.OpCode = EFI_IFR_REF_OP; Hyperlink.Header.Length = sizeof (EFI_IFR_REF); Hyperlink.FormId = FormId; Hyperlink.Prompt = StringToken; Hyperlink.Help = StringTokenTwo; Hyperlink.Key = Key; Hyperlink.Flags = Flags; EfiCopyMem (FormBuffer, &Hyperlink, sizeof (EFI_IFR_REF)); return EFI_SUCCESS; }
STATIC VOID MD5UpdateBlock ( IN MD5_CTX *Md5Ctx, IN CONST UINT8 *Data, IN UINTN DataLen ) /*++ Routine Description: GC_TODO: Add function description Arguments: Md5Ctx - GC_TODO: add argument description Data - GC_TODO: add argument description DataLen - GC_TODO: add argument description Returns: GC_TODO: add return values --*/ { UINTN Limit; for (Limit = 64 - Md5Ctx->Count; DataLen >= 64 - Md5Ctx->Count; Limit = 64) { EfiCopyMem (Md5Ctx->M + Md5Ctx->Count, (VOID *)Data, Limit); MD5Transform (Md5Ctx); Md5Ctx->Count = 0; Data += Limit; DataLen -= Limit; } EfiCopyMem (Md5Ctx->M + Md5Ctx->Count, (VOID *)Data, DataLen); Md5Ctx->Count += DataLen; }
EFI_DEVICE_PATH_PROTOCOL * DevicePathInstanceDup ( IN EFI_DEVICE_PATH_PROTOCOL *DevPath ) /*++ Routine Description: Function creates a device path data structure that identically matches the device path passed in. Arguments: DevPath - A pointer to a device path data structure. Returns: The new copy of DevPath is created to identically match the input. Otherwise, NULL is returned. --*/ { EFI_DEVICE_PATH_PROTOCOL *NewDevPath; EFI_DEVICE_PATH_PROTOCOL *DevicePathInst; EFI_DEVICE_PATH_PROTOCOL *Temp; UINT8 *Ptr; UINTN Size; // // get the size of an instance from the input // Temp = DevPath; DevicePathInst = EfiDevicePathInstance (&Temp, &Size); // // Make a copy and set proper end type // NewDevPath = NULL; if (Size) { NewDevPath = EfiAllocateZeroPool (Size); ASSERT (NewDevPath != NULL); } if (NewDevPath) { EfiCopyMem (NewDevPath, DevicePathInst, Size); Ptr = (UINT8 *) NewDevPath; Ptr += Size - sizeof (EFI_DEVICE_PATH_PROTOCOL); Temp = (EFI_DEVICE_PATH_PROTOCOL *) Ptr; SetDevicePathEndNode (Temp); } return NewDevPath; }
EFI_STATUS MD5Final ( IN MD5_CTX *Md5Ctx, OUT UINT8 *HashVal ) /*++ Routine Description: GC_TODO: Add function description Arguments: Md5Ctx - GC_TODO: add argument description HashVal - GC_TODO: add argument description Returns: EFI_SUCCESS - GC_TODO: Add description for return value --*/ { UINTN PadLength; if (Md5Ctx->Status == EFI_ALREADY_STARTED) { // // Store Hashed value & Zeroize sensitive context information. // EfiCopyMem (HashVal, (UINT8 *) Md5Ctx->States, MD5_HASHSIZE); EfiZeroMem ((UINT8 *)Md5Ctx, sizeof (*Md5Ctx)); return EFI_SUCCESS; } if (EFI_ERROR (Md5Ctx->Status)) { return Md5Ctx->Status; } PadLength = Md5Ctx->Count >= 56 ? 120 : 56; PadLength -= Md5Ctx->Count; MD5UpdateBlock (Md5Ctx, Md5HashPadding, PadLength); Md5Ctx->Length = LShiftU64 (Md5Ctx->Length, 3); MD5UpdateBlock (Md5Ctx, (CONST UINT8 *) &Md5Ctx->Length, 8); EfiZeroMem (Md5Ctx->M, sizeof (Md5Ctx->M)); Md5Ctx->Length = 0; Md5Ctx->Status = EFI_ALREADY_STARTED; return MD5Final (Md5Ctx, HashVal); }
EFI_STATUS EFIAPI AmdAddFchInjEntry ( IN OUT EINJ_INSTRUCTION_ENTRY *EntryPtr ) { EFI_STATUS Status; UINT16 SwSmiCmdAddress; Status = EFI_SUCCESS; SwSmiCmdAddress = ACPIMMIO16 (ACPI_MMIO_BASE + PMIO_BASE + FCH_PMIOA_REG6A); mAmdFchEinj.RegisterRegion.Address = (UINT64)SwSmiCmdAddress; EfiCopyMem (EntryPtr, &mAmdFchEinj, sizeof (EINJ_INSTRUCTION_ENTRY)); return Status; }
EFI_STATUS PushStack ( IN OUT EFI_HII_VALUE **Stack, IN OUT EFI_HII_VALUE **StackPtr, IN OUT EFI_HII_VALUE **StackEnd, IN EFI_HII_VALUE *Data ) /*++ Routine Description: Push an element onto the Boolean Stack Arguments: Stack - On input: old stack; On output: new stack StackPtr - On input: old stack pointer; On output: new stack pointer StackEnd - On input: old stack end; On output: new stack end Data - Data to push. Returns: EFI_SUCCESS - Push stack success. --*/ { EFI_STATUS Status; // // Check for a stack overflow condition // if (*StackPtr >= *StackEnd) { // // Grow the stack // Status = GrowStack (Stack, StackPtr, StackEnd); if (EFI_ERROR (Status)) { return Status; } } // // Push the item onto the stack // EfiCopyMem (*StackPtr, Data, sizeof (EFI_HII_VALUE)); *StackPtr = *StackPtr + 1; return EFI_SUCCESS; }
EFI_STATUS CreateStringOpCode ( IN EFI_QUESTION_ID QuestionId, IN EFI_VARSTORE_ID VarStoreId, IN UINT16 VarOffset, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN UINT8 StringFlags, IN UINT8 MinSize, IN UINT8 MaxSize, IN OUT EFI_HII_UPDATE_DATA *Data ) { EFI_IFR_STRING String; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if (!IsValidQuestionFlags (QuestionFlags) || (StringFlags & (~EFI_IFR_STRING_MULTI_LINE))) { return EFI_INVALID_PARAMETER; } if (Data->Offset + sizeof (EFI_IFR_STRING) > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } String.Header.OpCode = EFI_IFR_STRING_OP; String.Header.Length = (UINT8) sizeof (EFI_IFR_STRING); String.Header.Scope = 0; String.Question.Header.Prompt = Prompt; String.Question.Header.Help = Help; String.Question.QuestionId = QuestionId; String.Question.VarStoreId = VarStoreId; String.Question.VarStoreInfo.VarOffset = VarOffset; String.Question.Flags = QuestionFlags; String.MinSize = MinSize; String.MaxSize = MaxSize; String.Flags = StringFlags; LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &String, sizeof (EFI_IFR_STRING)); Data->Offset += sizeof (EFI_IFR_STRING); return EFI_SUCCESS; }
EFI_STATUS CreateCheckBoxOpCode ( IN EFI_QUESTION_ID QuestionId, IN EFI_VARSTORE_ID VarStoreId, IN UINT16 VarOffset, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN UINT8 CheckBoxFlags, IN OUT EFI_HII_UPDATE_DATA *Data ) { EFI_IFR_CHECKBOX CheckBox; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if (!IsValidQuestionFlags (QuestionFlags) || !IsValidCheckboxFlags (CheckBoxFlags)) { return EFI_INVALID_PARAMETER; } if (Data->Offset + sizeof (EFI_IFR_CHECKBOX) > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP; CheckBox.Header.Length = (UINT8) sizeof (EFI_IFR_CHECKBOX); CheckBox.Header.Scope = 0; CheckBox.Question.QuestionId = QuestionId; CheckBox.Question.VarStoreId = VarStoreId; CheckBox.Question.VarStoreInfo.VarOffset = VarOffset; CheckBox.Question.Header.Prompt = Prompt; CheckBox.Question.Header.Help = Help; CheckBox.Question.Flags = QuestionFlags; CheckBox.Flags = CheckBoxFlags; LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &CheckBox, sizeof (EFI_IFR_CHECKBOX)); Data->Offset += sizeof (EFI_IFR_CHECKBOX); return EFI_SUCCESS; }
EFI_STATUS CreateActionOpCode ( IN EFI_QUESTION_ID QuestionId, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN EFI_STRING_ID QuestionConfig, IN OUT EFI_HII_UPDATE_DATA *Data ) { EFI_IFR_ACTION Action; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if (!IsValidQuestionFlags (QuestionFlags)) { return EFI_INVALID_PARAMETER; } if (Data->Offset + sizeof (EFI_IFR_ACTION) > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } Action.Header.OpCode = EFI_IFR_ACTION_OP; Action.Header.Length = (UINT8) sizeof (EFI_IFR_ACTION); Action.Header.Scope = 0; Action.Question.QuestionId = QuestionId; Action.Question.Header.Prompt = Prompt; Action.Question.Header.Help = Help; Action.Question.VarStoreId = INVALID_VARSTORE_ID; Action.Question.Flags = QuestionFlags; Action.QuestionConfig = QuestionConfig; LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &Action, sizeof (EFI_IFR_ACTION)); Data->Offset += sizeof (EFI_IFR_ACTION); return EFI_SUCCESS; }
EFI_STATUS CreateOneOfOptionOpCode ( IN UINTN OptionCount, IN IFR_OPTION *OptionsList, IN UINT8 Type, IN OUT EFI_HII_UPDATE_DATA *Data ) { UINTN Index; UINT8 *LocalBuffer; EFI_IFR_ONE_OF_OPTION OneOfOption; ASSERT (Data != NULL && Data->Data != NULL); if ((OptionCount != 0) && (OptionsList == NULL)) { return EFI_INVALID_PARAMETER; } if (Data->Offset + OptionCount * sizeof (EFI_IFR_ONE_OF_OPTION) > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } for (Index = 0; Index < OptionCount; Index++) { OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP; OneOfOption.Header.Length = (UINT8) sizeof (EFI_IFR_ONE_OF_OPTION); OneOfOption.Header.Scope = 0; OneOfOption.Option = OptionsList[Index].StringToken; OneOfOption.Value = OptionsList[Index].Value; OneOfOption.Flags = (UINT8)(OptionsList[Index].Flags & (EFI_IFR_OPTION_DEFAULT | EFI_IFR_OPTION_DEFAULT_MFG)); OneOfOption.Type = Type; LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &OneOfOption, sizeof (EFI_IFR_ONE_OF_OPTION)); Data->Offset += sizeof (EFI_IFR_ONE_OF_OPTION); } return EFI_SUCCESS; }
EFI_STATUS CreateGotoOpCode ( IN EFI_FORM_ID FormId, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN EFI_QUESTION_ID QuestionId, IN OUT EFI_HII_UPDATE_DATA *Data ) { EFI_IFR_REF Goto; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if (!IsValidQuestionFlags (QuestionFlags)) { return EFI_INVALID_PARAMETER; } if (Data->Offset + sizeof (EFI_IFR_REF) > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } Goto.Header.OpCode = EFI_IFR_REF_OP; Goto.Header.Length = (UINT8) sizeof (EFI_IFR_REF); Goto.Header.Scope = 0; Goto.Question.Header.Prompt = Prompt; Goto.Question.Header.Help = Help; Goto.Question.VarStoreId = INVALID_VARSTORE_ID; Goto.Question.QuestionId = QuestionId; Goto.Question.Flags = QuestionFlags; Goto.FormId = FormId; LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &Goto, sizeof (EFI_IFR_REF)); Data->Offset += sizeof (EFI_IFR_REF); return EFI_SUCCESS; }
STATIC EFI_STATUS EFIAPI WinNtGopSimpleTextInReadKeyStroke ( IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This, OUT EFI_INPUT_KEY *Key ) /*++ Routine Description: TODO: Add function description Arguments: This - TODO: add argument description Key - TODO: add argument description Returns: TODO: add return values --*/ { GOP_PRIVATE_DATA *Private; EFI_STATUS Status; EFI_KEY_DATA KeyData; Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This); Status = GopPrivateReadKeyStrokeWorker (Private, &KeyData); if (EFI_ERROR (Status)) { return Status; } EfiCopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY)); return EFI_SUCCESS; }
EFI_STATUS PopStack ( IN OUT EFI_HII_VALUE **Stack, IN OUT EFI_HII_VALUE **StackPtr, IN OUT EFI_HII_VALUE **StackEnd, OUT EFI_HII_VALUE *Data ) /*++ Routine Description: Pop an element from the stack. Arguments: Stack - On input: old stack; On output: new stack StackPtr - On input: old stack pointer; On output: new stack pointer StackEnd - On input: old stack end; On output: new stack end Data - Data to pop. Returns: EFI_SUCCESS - The value was popped onto the stack. EFI_ACCESS_DENIED - The pop operation underflowed the stack --*/ { // // Check for a stack underflow condition // if (*StackPtr == *Stack) { return EFI_ACCESS_DENIED; } // // Pop the item off the stack // *StackPtr = *StackPtr - 1; EfiCopyMem (Data, *StackPtr, sizeof (EFI_HII_VALUE)); return EFI_SUCCESS; }
EFI_STATUS CreateEndOpCode ( IN OUT EFI_HII_UPDATE_DATA *Data ) { EFI_IFR_END End; UINT8 *LocalBuffer; ASSERT (Data != NULL && Data->Data != NULL); if (Data->Offset + sizeof (EFI_IFR_END) > Data->BufferSize) { return EFI_BUFFER_TOO_SMALL; } End.Header.Length = (UINT8) sizeof (EFI_IFR_END); End.Header.OpCode = EFI_IFR_END_OP; End.Header.Scope = 0; LocalBuffer = (UINT8 *) Data->Data + Data->Offset; EfiCopyMem (LocalBuffer, &End, sizeof (EFI_IFR_END)); Data->Offset += sizeof (EFI_IFR_END); return EFI_SUCCESS; }
VOID WriteBootToOsPerformanceData ( VOID ) /*++ Routine Description: Allocates a block of memory and writes performance data of booting to OS into it. Arguments: None Returns: None --*/ { EFI_STATUS Status; EFI_CPU_ARCH_PROTOCOL *Cpu; EFI_PERFORMANCE_PROTOCOL *DrvPerf; UINT32 mAcpiLowMemoryLength; UINT32 LimitCount; EFI_PERF_HEADER mPerfHeader; EFI_PERF_DATA mPerfData; EFI_GAUGE_DATA *DumpData; EFI_HANDLE *Handles; UINTN NoHandles; UINT8 *Ptr; UINT8 *PdbFileName; UINT32 mIndex; UINT64 Ticker; UINT64 Freq; UINT32 Duration; UINT64 CurrentTicker; UINT64 TimerPeriod; // // Retrive time stamp count as early as possilbe // Ticker = EfiReadTsc (); // // Get performance architecture protocol // Status = gBS->LocateProtocol ( &gEfiPerformanceProtocolGuid, NULL, &DrvPerf ); if (EFI_ERROR (Status)) { return ; } // // Get CPU frequency // Status = gBS->LocateProtocol ( &gEfiCpuArchProtocolGuid, NULL, &Cpu ); if (EFI_ERROR (Status)) { return ; } // // Get Cpu Frequency // Status = Cpu->GetTimerValue (Cpu, 0, &CurrentTicker, &TimerPeriod); if (EFI_ERROR (Status)) { return ; } // // Put Detailed performance data into memory // Handles = NULL; Status = gBS->LocateHandleBuffer ( AllHandles, NULL, NULL, &NoHandles, &Handles ); if (EFI_ERROR (Status)) { return ; } // // Allocate a block of memory that contain performance data to OS // if it is not allocated yet. // if (mAcpiLowMemoryBase == 0x0FFFFFFFF) { Status = gBS->AllocatePages ( AllocateMaxAddress, EfiReservedMemoryType, 4, &mAcpiLowMemoryBase ); if (EFI_ERROR (Status)) { gBS->FreePool (Handles); return ; } } mAcpiLowMemoryLength = EFI_PAGES_TO_SIZE(4); Ptr = (UINT8 *) ((UINT32) mAcpiLowMemoryBase + sizeof (EFI_PERF_HEADER)); LimitCount = (mAcpiLowMemoryLength - sizeof (EFI_PERF_HEADER)) / sizeof (EFI_PERF_DATA); // // Initialize performance data structure // EfiZeroMem (&mPerfHeader, sizeof (EFI_PERF_HEADER)); Freq = DivU64x32 (1000000000000, (UINTN) TimerPeriod, NULL); mPerfHeader.CpuFreq = Freq; // // Record BDS raw performance data // mPerfHeader.BDSRaw = Ticker; // // Get DXE drivers performance // for (mIndex = 0; mIndex < NoHandles; mIndex++) { Ticker = 0; PdbFileName = NULL; DumpData = DrvPerf->GetGauge ( DrvPerf, // Context NULL, // Handle NULL, // Token NULL, // Host NULL // PrecGauge ); while (DumpData) { if (DumpData->Handle == Handles[mIndex]) { PdbFileName = &(DumpData->PdbFileName[0]); if (DumpData->StartTick < DumpData->EndTick) { Ticker += (DumpData->EndTick - DumpData->StartTick); } } DumpData = DrvPerf->GetGauge ( DrvPerf, // Context NULL, // Handle NULL, // Token NULL, // Host DumpData // PrecGauge ); } Duration = (UINT32) DivU64x32 ( Ticker, (UINT32) Freq, NULL ); if (Duration > 0) { EfiZeroMem (&mPerfData, sizeof (EFI_PERF_DATA)); if (PdbFileName != NULL) { EfiAsciiStrCpy (mPerfData.Token, PdbFileName); } mPerfData.Duration = Duration; EfiCopyMem (Ptr, &mPerfData, sizeof (EFI_PERF_DATA)); Ptr += sizeof (EFI_PERF_DATA); mPerfHeader.Count++; if (mPerfHeader.Count == LimitCount) { goto Done; } } } gBS->FreePool (Handles); // // Get inserted performance data // DumpData = DrvPerf->GetGauge ( DrvPerf, // Context NULL, // Handle NULL, // Token NULL, // Host NULL // PrecGauge ); while (DumpData) { if ((DumpData->Handle) || (DumpData->StartTick > DumpData->EndTick)) { DumpData = DrvPerf->GetGauge ( DrvPerf, // Context NULL, // Handle NULL, // Token NULL, // Host DumpData // PrecGauge ); continue; } EfiZeroMem (&mPerfData, sizeof (EFI_PERF_DATA)); ConvertChar16ToChar8 ((UINT8 *) mPerfData.Token, DumpData->Token); mPerfData.Duration = (UINT32) DivU64x32 ( DumpData->EndTick - DumpData->StartTick, (UINT32) Freq, NULL ); EfiCopyMem (Ptr, &mPerfData, sizeof (EFI_PERF_DATA)); Ptr += sizeof (EFI_PERF_DATA); mPerfHeader.Count++; if (mPerfHeader.Count == LimitCount) { goto Done; } DumpData = DrvPerf->GetGauge ( DrvPerf, // Context NULL, // Handle NULL, // Token NULL, // Host DumpData // PrecGauge ); } Done: mPerfHeader.Signiture = 0x66726550; // // Put performance data to memory // EfiCopyMem ( (UINTN *) (UINTN) mAcpiLowMemoryBase, &mPerfHeader, sizeof (EFI_PERF_HEADER) ); gRT->SetVariable ( L"PerfDataMemAddr", &gEfiGenericVariableGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, sizeof (UINT32), (VOID *) &mAcpiLowMemoryBase ); return ; }
EFI_STATUS EFIAPI WinNtGopSimpleTextInExRegisterKeyNotify ( IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_DATA *KeyData, IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction, OUT EFI_HANDLE *NotifyHandle ) /*++ Routine Description: Register a notification function for a particular keystroke for the input device. Arguments: This - Protocol instance pointer. KeyData - A pointer to a buffer that is filled in with the keystroke information data for the key that was pressed. KeyNotificationFunction - Points to the function to be called when the key sequence is typed specified by KeyData. NotifyHandle - Points to the unique handle assigned to the registered notification. Returns: EFI_SUCCESS - The notification function was registered successfully. EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures. EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL. --*/ { EFI_STATUS Status; GOP_PRIVATE_DATA *Private; WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify; EFI_LIST_ENTRY *Link; WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NewNotify; if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) { return EFI_INVALID_PARAMETER; } Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This); // // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered. // for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) { CurrentNotify = CR ( Link, WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY, NotifyEntry, WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE ); if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) { *NotifyHandle = CurrentNotify->NotifyHandle; return EFI_SUCCESS; } } } // // Allocate resource to save the notification function // NewNotify = (WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) EfiLibAllocateZeroPool (sizeof (WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY)); if (NewNotify == NULL) { return EFI_OUT_OF_RESOURCES; } NewNotify->Signature = WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE; NewNotify->KeyNotificationFn = KeyNotificationFunction; EfiCopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData)); InsertTailList (&Private->NotifyList, &NewNotify->NotifyEntry); // // Use gSimpleTextInExNotifyGuid to get a valid EFI_HANDLE // Status = gBS->InstallMultipleProtocolInterfaces ( &NewNotify->NotifyHandle, &gSimpleTextInExNotifyGuid, NULL, NULL ); ASSERT_EFI_ERROR (Status); *NotifyHandle = NewNotify->NotifyHandle; return EFI_SUCCESS; }
BOOLEAN IsTerminalDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT TYPE_OF_TERMINAL *Termi, OUT UINTN *Com ) /*++ Routine Description: Test whether DevicePath is a valid Terminal Arguments: DevicePath - DevicePath to be checked Termi - If is terminal, give its type Com - If is Com Port, give its type Returns: TRUE - If DevicePath point to a Terminal FALSE --*/ { UINT8 *Ptr; BOOLEAN IsTerminal; VENDOR_DEVICE_PATH *Vendor; ACPI_HID_DEVICE_PATH *Acpi; UINT32 Match; EFI_GUID TempGuid; IsTerminal = FALSE; // // Parse the Device Path, should be change later!!! // Ptr = (UINT8 *) DevicePath; while (*Ptr != END_DEVICE_PATH_TYPE) { Ptr++; } Ptr = Ptr - sizeof (VENDOR_DEVICE_PATH); Vendor = (VENDOR_DEVICE_PATH *) Ptr; // // There are four kinds of Terminal types // check to see whether this devicepath // is one of that type // EfiCopyMem (&TempGuid, &Vendor->Guid, sizeof (EFI_GUID)); if (EfiCompareGuid (&TempGuid, &Guid[0])) { *Termi = PC_ANSI; IsTerminal = TRUE; } else { if (EfiCompareGuid (&TempGuid, &Guid[1])) { *Termi = VT_100; IsTerminal = TRUE; } else { if (EfiCompareGuid (&TempGuid, &Guid[2])) { *Termi = VT_100_PLUS; IsTerminal = TRUE; } else { if (EfiCompareGuid (&TempGuid, &Guid[3])) { *Termi = VT_UTF8; IsTerminal = TRUE; } else { IsTerminal = FALSE; } } } } if (!IsTerminal) { return FALSE; } Ptr = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH); Acpi = (ACPI_HID_DEVICE_PATH *) Ptr; Match = EISA_PNP_ID (0x0501); if (EfiCompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) { EfiCopyMem (Com, &Acpi->UID, sizeof (UINT32)); } else { return FALSE; } return TRUE; }