3 Vfr common library functions.
5 Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include "CommonLib.h"
14 #include "VfrUtilityLib.h"
15 #include "VfrFormPkg.h"
18 CVfrBinaryOutput::WriteLine (
21 IN CONST CHAR8
*LineHeader
,
28 if ((pFile
== NULL
) || (LineHeader
== NULL
) || (BlkBuf
== NULL
)) {
32 for (Index
= 0; Index
< BlkSize
; Index
++) {
33 if ((Index
% LineBytes
) == 0) {
34 fprintf (pFile
, "\n%s", LineHeader
);
36 fprintf (pFile
, "0x%02X, ", (UINT8
)BlkBuf
[Index
]);
41 CVfrBinaryOutput::WriteEnd (
44 IN CONST CHAR8
*LineHeader
,
51 if ((BlkSize
== 0) || (pFile
== NULL
) || (LineHeader
== NULL
) || (BlkBuf
== NULL
)) {
55 for (Index
= 0; Index
< BlkSize
- 1; Index
++) {
56 if ((Index
% LineBytes
) == 0) {
57 fprintf (pFile
, "\n%s", LineHeader
);
59 fprintf (pFile
, "0x%02X, ", (UINT8
)BlkBuf
[Index
]);
62 if ((Index
% LineBytes
) == 0) {
63 fprintf (pFile
, "\n%s", LineHeader
);
65 fprintf (pFile
, "0x%02X\n", (UINT8
)BlkBuf
[Index
]);
68 SConfigInfo::SConfigInfo (
72 IN EFI_IFR_TYPE_VALUE Value
77 mWidth
= (UINT16
)Width
;
78 mValue
= new UINT8
[mWidth
];
84 case EFI_IFR_TYPE_NUM_SIZE_8
:
85 memcpy (mValue
, &Value
.u8
, mWidth
);
87 case EFI_IFR_TYPE_NUM_SIZE_16
:
88 memcpy (mValue
, &Value
.u16
, mWidth
);
90 case EFI_IFR_TYPE_NUM_SIZE_32
:
91 memcpy (mValue
, &Value
.u32
, mWidth
);
93 case EFI_IFR_TYPE_NUM_SIZE_64
:
94 memcpy (mValue
, &Value
.u64
, mWidth
);
96 case EFI_IFR_TYPE_BOOLEAN
:
97 memcpy (mValue
, &Value
.b
, mWidth
);
99 case EFI_IFR_TYPE_TIME
:
100 memcpy (mValue
, &Value
.time
, mWidth
);
102 case EFI_IFR_TYPE_DATE
:
103 memcpy (mValue
, &Value
.date
, mWidth
);
105 case EFI_IFR_TYPE_STRING
:
106 memcpy (mValue
, &Value
.string
, mWidth
);
108 case EFI_IFR_TYPE_BUFFER
:
109 memcpy (mValue
, &Value
.u8
, mWidth
);
112 case EFI_IFR_TYPE_OTHER
:
117 SConfigInfo::~SConfigInfo (
121 ARRAY_SAFE_FREE (mValue
);
124 SConfigItem::SConfigItem (
137 if ((mName
= new CHAR8
[strlen (Name
) + 1]) != NULL
) {
138 strcpy (mName
, Name
);
143 if ((mGuid
= (EFI_GUID
*) new CHAR8
[sizeof (EFI_GUID
)]) != NULL
) {
144 memcpy (mGuid
, Guid
, sizeof (EFI_GUID
));
149 if ((mId
= new CHAR8
[strlen (Id
) + 1]) != NULL
) {
155 SConfigItem::SConfigItem (
162 IN EFI_IFR_TYPE_VALUE Value
172 if ((mName
= new CHAR8
[strlen (Name
) + 1]) != NULL
) {
173 strcpy (mName
, Name
);
178 if ((mGuid
= (EFI_GUID
*) new CHAR8
[sizeof (EFI_GUID
)]) != NULL
) {
179 memcpy (mGuid
, Guid
, sizeof (EFI_GUID
));
184 if ((mId
= new CHAR8
[strlen (Id
) + 1]) != NULL
) {
189 mInfoStrList
= new SConfigInfo(Type
, Offset
, Width
, Value
);
192 SConfigItem::~SConfigItem (
198 ARRAY_SAFE_FREE (mName
);
199 ARRAY_SAFE_FREE (mGuid
);
200 ARRAY_SAFE_FREE (mId
);
201 while (mInfoStrList
!= NULL
) {
203 mInfoStrList
= mInfoStrList
->mNext
;
205 BUFFER_SAFE_FREE (Info
);
210 CVfrBufferConfig::Register (
218 if (Select (Name
, Guid
) == 0) {
222 if ((pNew
= new SConfigItem (Name
, Guid
, Id
)) == NULL
) {
226 if (mItemListHead
== NULL
) {
227 mItemListHead
= pNew
;
228 mItemListTail
= pNew
;
230 mItemListTail
->mNext
= pNew
;
231 mItemListTail
= pNew
;
239 CVfrBufferConfig::Open (
243 mItemListPos
= mItemListHead
;
247 CVfrBufferConfig::Eof(
251 return (mItemListPos
== NULL
) ? TRUE
: FALSE
;
255 CVfrBufferConfig::Select (
263 if (Name
== NULL
|| Guid
== NULL
) {
264 mItemListPos
= mItemListHead
;
267 for (p
= mItemListHead
; p
!= NULL
; p
= p
->mNext
) {
268 if ((strcmp (p
->mName
, Name
) != 0) || (memcmp (p
->mGuid
, Guid
, sizeof (EFI_GUID
)) != 0)) {
273 if (p
->mId
== NULL
|| strcmp (p
->mId
, Id
) != 0) {
276 } else if (p
->mId
!= NULL
) {
289 CVfrBufferConfig::Write (
297 IN EFI_IFR_TYPE_VALUE Value
304 if ((Ret
= Select (Name
, Guid
)) != 0) {
310 if (Select (Name
, Guid
, Id
) != 0) {
311 if ((pItem
= new SConfigItem (Name
, Guid
, Id
, Type
, Offset
, (UINT16
) Width
, Value
)) == NULL
) {
314 if (mItemListHead
== NULL
) {
315 mItemListHead
= pItem
;
316 mItemListTail
= pItem
;
318 mItemListTail
->mNext
= pItem
;
319 mItemListTail
= pItem
;
321 mItemListPos
= pItem
;
323 // tranverse the list to find out if there's already the value for the same offset
324 for (pInfo
= mItemListPos
->mInfoStrList
; pInfo
!= NULL
; pInfo
= pInfo
->mNext
) {
325 if (pInfo
->mOffset
== Offset
) {
329 if((pInfo
= new SConfigInfo (Type
, Offset
, Width
, Value
)) == NULL
) {
332 pInfo
->mNext
= mItemListPos
->mInfoStrList
;
333 mItemListPos
->mInfoStrList
= pInfo
;
338 if (mItemListHead
== mItemListPos
) {
339 mItemListHead
= mItemListPos
->mNext
;
344 for (pItem
= mItemListHead
; pItem
->mNext
!= mItemListPos
; pItem
= pItem
->mNext
)
347 pItem
->mNext
= mItemListPos
->mNext
;
348 if (mItemListTail
== mItemListPos
) {
349 mItemListTail
= pItem
;
352 mItemListPos
= pItem
->mNext
;
355 case 'i' : // set info
356 if (mItemListPos
->mId
!= NULL
) {
357 delete[] mItemListPos
->mId
;
359 mItemListPos
->mId
= NULL
;
361 if ((mItemListPos
->mId
= new CHAR8
[strlen (Id
) + 1]) == NULL
) {
364 strcpy (mItemListPos
->mId
, Id
);
377 CVfrBufferConfig::Close (
384 #define BYTES_PRE_LINE 0x10
387 CVfrBufferConfig::OutputCFile (
392 CVfrBinaryOutput Output
;
401 for (Item
= mItemListHead
; Item
!= NULL
; Item
= Item
->mNext
) {
402 if (Item
->mId
!= NULL
|| Item
->mInfoStrList
== NULL
) {
405 fprintf (pFile
, "\nunsigned char %s%sBlockName[] = {", BaseName
, Item
->mName
);
407 TotalLen
= sizeof (UINT32
);
408 for (Info
= Item
->mInfoStrList
; Info
!= NULL
; Info
= Info
->mNext
) {
409 TotalLen
+= sizeof (UINT16
) * 2;
411 Output
.WriteLine (pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&TotalLen
, sizeof (UINT32
));
413 for (Info
= Item
->mInfoStrList
; Info
!= NULL
; Info
= Info
->mNext
) {
414 fprintf (pFile
, "\n");
415 Output
.WriteLine (pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&Info
->mOffset
, sizeof (UINT16
));
416 Output
.WriteLine (pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&Info
->mWidth
, sizeof (UINT16
));
418 fprintf (pFile
, "\n};\n");
421 for (Item
= mItemListHead
; Item
!= NULL
; Item
= Item
->mNext
) {
422 if (Item
->mId
!= NULL
&& Item
->mInfoStrList
!= NULL
) {
423 fprintf (pFile
, "\nunsigned char %s%sDefault%s[] = {", BaseName
, Item
->mName
, Item
->mId
);
425 TotalLen
= sizeof (UINT32
);
426 for (Info
= Item
->mInfoStrList
; Info
!= NULL
; Info
= Info
->mNext
) {
427 TotalLen
+= Info
->mWidth
+ sizeof (UINT16
) * 2;
429 Output
.WriteLine (pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&TotalLen
, sizeof (UINT32
));
431 for (Info
= Item
->mInfoStrList
; Info
!= NULL
; Info
= Info
->mNext
) {
432 fprintf (pFile
, "\n");
433 Output
.WriteLine (pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&Info
->mOffset
, sizeof (UINT16
));
434 Output
.WriteLine (pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&Info
->mWidth
, sizeof (UINT16
));
435 if (Info
->mNext
== NULL
) {
436 Output
.WriteEnd (pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)Info
->mValue
, Info
->mWidth
);
438 Output
.WriteLine (pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)Info
->mValue
, Info
->mWidth
);
441 fprintf (pFile
, "\n};\n");
446 CVfrBufferConfig::CVfrBufferConfig (
450 mItemListHead
= NULL
;
451 mItemListTail
= NULL
;
455 CVfrBufferConfig::~CVfrBufferConfig (
461 while (mItemListHead
!= NULL
) {
463 mItemListHead
= mItemListHead
->mNext
;
467 mItemListHead
= NULL
;
468 mItemListTail
= NULL
;
472 CVfrBufferConfig gCVfrBufferConfig
;
475 CONST CHAR8
*mTypeName
;
479 } gInternalTypesTable
[] = {
480 {"UINT64", EFI_IFR_TYPE_NUM_SIZE_64
, sizeof (UINT64
), sizeof (UINT64
)},
481 {"UINT32", EFI_IFR_TYPE_NUM_SIZE_32
, sizeof (UINT32
), sizeof (UINT32
)},
482 {"UINT16", EFI_IFR_TYPE_NUM_SIZE_16
, sizeof (UINT16
), sizeof (UINT16
)},
483 {"UINT8", EFI_IFR_TYPE_NUM_SIZE_8
, sizeof (UINT8
), sizeof (UINT8
)},
484 {"BOOLEAN", EFI_IFR_TYPE_BOOLEAN
, sizeof (BOOLEAN
), sizeof (BOOLEAN
)},
485 {"EFI_HII_DATE", EFI_IFR_TYPE_DATE
, sizeof (EFI_HII_DATE
), sizeof (UINT16
)},
486 {"EFI_STRING_ID", EFI_IFR_TYPE_STRING
, sizeof (EFI_STRING_ID
),sizeof (EFI_STRING_ID
)},
487 {"EFI_HII_TIME", EFI_IFR_TYPE_TIME
, sizeof (EFI_HII_TIME
), sizeof (UINT8
)},
488 {"EFI_HII_REF", EFI_IFR_TYPE_REF
, sizeof (EFI_HII_REF
), sizeof (EFI_GUID
)},
489 {NULL
, EFI_IFR_TYPE_OTHER
, 0, 0}
500 if (TypeName
== NULL
) {
504 for (Index
= 0; gInternalTypesTable
[Index
].mTypeName
!= NULL
; Index
++) {
505 if (strcmp (TypeName
, gInternalTypesTable
[Index
].mTypeName
) == 0) {
522 while (*Str
&& *Str
== ' ') {
525 while (*Str
&& *Str
== '0') {
528 if (*Str
&& (*Str
== 'x' || *Str
== 'X')) {
545 Str
= TrimHex (Str
, &IsHex
);
546 for (Value
= 0; (c
= *Str
) != '\0'; Str
++) {
548 // BUG: does not handle overflow here
550 (IsHex
== TRUE
) ? (Value
<<= 4) : (Value
*= 10);
552 if ((IsHex
== TRUE
) && (c
>= 'a') && (c
<= 'f')) {
553 Value
+= (c
- 'a' + 10);
555 if ((IsHex
== TRUE
) && (c
>= 'A') && (c
<= 'F')) {
556 Value
+= (c
- 'A' + 10);
558 if (c
>= '0' && c
<= '9') {
567 CVfrVarDataTypeDB::RegisterNewType (
571 New
->mNext
= mDataTypeList
;
576 CVfrVarDataTypeDB::ExtractStructTypeName (
582 return VFR_RETURN_FATAL_ERROR
;
585 while((*VarStr
!= '\0') && (*VarStr
!= '.')) {
591 if (*VarStr
== '.') {
595 return VFR_RETURN_SUCCESS
;
599 Check whether the DataType contain bit field.
601 @param TypeName The name of the type.
605 CVfrVarDataTypeDB::DataTypeHasBitField (
609 SVfrDataType
*pType
= NULL
;
612 GetDataType (TypeName
, &pType
);
617 for (pTmp
= pType
->mMembers
; pTmp
!= NULL
; pTmp
= pTmp
->mNext
) {
618 if (pTmp
->mIsBitField
) {
626 Check whether the field is bit field or not.
628 @param VarStr Point to the field name which may contain the structure name.
632 CVfrVarDataTypeDB::IsThisBitField (
636 CHAR8 FName
[MAX_NAME_LEN
];
637 CHAR8 TName
[MAX_NAME_LEN
];
639 SVfrDataType
*pType
= NULL
;
640 SVfrDataField
*pField
= NULL
;
642 CHECK_ERROR_RETURN (ExtractStructTypeName (VarStr
, TName
), VFR_RETURN_SUCCESS
);
643 CHECK_ERROR_RETURN (GetDataType (TName
, &pType
), VFR_RETURN_SUCCESS
);
645 while (*VarStr
!= '\0') {
646 CHECK_ERROR_RETURN(ExtractFieldNameAndArrary(VarStr
, FName
, ArrayIdx
), VFR_RETURN_SUCCESS
);
647 CHECK_ERROR_RETURN(GetTypeField (FName
, pType
, pField
), VFR_RETURN_SUCCESS
);
648 pType
= pField
->mFieldType
;
650 if (pField
!= NULL
&& pField
->mIsBitField
) {
658 CVfrVarDataTypeDB::ExtractFieldNameAndArrary (
665 CHAR8 ArrayStr
[MAX_NAME_LEN
+ 1];
667 ArrayIdx
= INVALID_ARRAY_INDEX
;
670 return VFR_RETURN_FATAL_ERROR
;
673 while((*VarStr
!= '\0') &&
687 return VFR_RETURN_SUCCESS
;
690 for (Idx
= 0; (Idx
< MAX_NAME_LEN
) && (*VarStr
!= '\0') && (*VarStr
!= ']'); VarStr
++, Idx
++) {
691 ArrayStr
[Idx
] = *VarStr
;
693 ArrayStr
[Idx
] = '\0';
695 if ((*VarStr
!= ']') && (ArrayStr
[0] == '\0')) {
696 return VFR_RETURN_DATA_STRING_ERROR
;
698 ArrayIdx
= _STR2U32 (ArrayStr
);
699 if (*VarStr
== ']') {
702 if (*VarStr
== '.') {
705 return VFR_RETURN_SUCCESS
;
707 return VFR_RETURN_DATA_STRING_ERROR
;
710 return VFR_RETURN_SUCCESS
;
714 CVfrVarDataTypeDB::GetTypeField (
715 IN CONST CHAR8
*FName
,
716 IN SVfrDataType
*Type
,
717 OUT SVfrDataField
*&Field
720 SVfrDataField
*pField
= NULL
;
722 if ((FName
== NULL
) || (Type
== NULL
)) {
723 return VFR_RETURN_FATAL_ERROR
;
726 for (pField
= Type
->mMembers
; pField
!= NULL
; pField
= pField
->mNext
) {
728 // For type EFI_IFR_TYPE_TIME, because field name is not correctly wrote,
729 // add code to adjust it.
731 if (Type
->mType
== EFI_IFR_TYPE_TIME
) {
732 if (strcmp (FName
, "Hour") == 0) {
734 } else if (strcmp (FName
, "Minute") == 0) {
736 } else if (strcmp (FName
, "Second") == 0) {
741 if (strcmp (pField
->mFieldName
, FName
) == 0) {
743 return VFR_RETURN_SUCCESS
;
747 return VFR_RETURN_UNDEFINED
;
751 CVfrVarDataTypeDB::GetFieldOffset (
752 IN SVfrDataField
*Field
,
755 IN BOOLEAN IsBitField
759 return VFR_RETURN_FATAL_ERROR
;
762 if ((ArrayIdx
!= INVALID_ARRAY_INDEX
) && ((Field
->mArrayNum
== 0) || (Field
->mArrayNum
<= ArrayIdx
))) {
763 return VFR_RETURN_ERROR_ARRARY_NUM
;
767 // Be compatible with the current usage
768 // If ArraryIdx is not specified, the first one is used.
770 // if ArrayNum is larger than zero, ArraryIdx must be specified.
772 // if ((ArrayIdx == INVALID_ARRAY_INDEX) && (Field->mArrayNum > 0)) {
773 // return VFR_RETURN_ERROR_ARRARY_NUM;
777 Offset
= Field
->mBitOffset
+ Field
->mFieldType
->mTotalSize
* ((ArrayIdx
== INVALID_ARRAY_INDEX
) ? 0 : ArrayIdx
) * 8;
779 Offset
= Field
->mOffset
+ Field
->mFieldType
->mTotalSize
* ((ArrayIdx
== INVALID_ARRAY_INDEX
) ? 0 : ArrayIdx
);
781 return VFR_RETURN_SUCCESS
;
785 CVfrVarDataTypeDB::GetFieldWidth (
786 IN SVfrDataField
*Field
793 return Field
->mFieldType
->mType
;
797 CVfrVarDataTypeDB::GetFieldSize (
798 IN SVfrDataField
*Field
,
804 return VFR_RETURN_FATAL_ERROR
;
807 if ((ArrayIdx
== INVALID_ARRAY_INDEX
) && (Field
->mArrayNum
!= 0)) {
808 return Field
->mFieldType
->mTotalSize
* Field
->mArrayNum
;
811 return Field
->mBitWidth
;
813 return Field
->mFieldType
->mTotalSize
;
819 CVfrVarDataTypeDB::InternalTypesListInit (
823 SVfrDataType
*New
= NULL
;
826 for (Index
= 0; gInternalTypesTable
[Index
].mTypeName
!= NULL
; Index
++) {
827 New
= new SVfrDataType
;
829 assert (strlen (gInternalTypesTable
[Index
].mTypeName
) < MAX_NAME_LEN
);
830 strncpy (New
->mTypeName
, gInternalTypesTable
[Index
].mTypeName
, MAX_NAME_LEN
- 1);
831 New
->mTypeName
[MAX_NAME_LEN
- 1] = 0;
832 New
->mType
= gInternalTypesTable
[Index
].mType
;
833 New
->mAlign
= gInternalTypesTable
[Index
].mAlign
;
834 New
->mTotalSize
= gInternalTypesTable
[Index
].mSize
;
835 if (strcmp (gInternalTypesTable
[Index
].mTypeName
, "EFI_HII_DATE") == 0) {
836 SVfrDataField
*pYearField
= new SVfrDataField
;
837 SVfrDataField
*pMonthField
= new SVfrDataField
;
838 SVfrDataField
*pDayField
= new SVfrDataField
;
840 strcpy (pYearField
->mFieldName
, "Year");
841 GetDataType ((CHAR8
*)"UINT16", &pYearField
->mFieldType
);
842 pYearField
->mOffset
= 0;
843 pYearField
->mNext
= pMonthField
;
844 pYearField
->mArrayNum
= 0;
845 pYearField
->mIsBitField
= FALSE
;
847 strcpy (pMonthField
->mFieldName
, "Month");
848 GetDataType ((CHAR8
*)"UINT8", &pMonthField
->mFieldType
);
849 pMonthField
->mOffset
= 2;
850 pMonthField
->mNext
= pDayField
;
851 pMonthField
->mArrayNum
= 0;
852 pMonthField
->mIsBitField
= FALSE
;
854 strcpy (pDayField
->mFieldName
, "Day");
855 GetDataType ((CHAR8
*)"UINT8", &pDayField
->mFieldType
);
856 pDayField
->mOffset
= 3;
857 pDayField
->mNext
= NULL
;
858 pDayField
->mArrayNum
= 0;
859 pDayField
->mIsBitField
= FALSE
;
861 New
->mMembers
= pYearField
;
862 } else if (strcmp (gInternalTypesTable
[Index
].mTypeName
, "EFI_HII_TIME") == 0) {
863 SVfrDataField
*pHoursField
= new SVfrDataField
;
864 SVfrDataField
*pMinutesField
= new SVfrDataField
;
865 SVfrDataField
*pSecondsField
= new SVfrDataField
;
867 strcpy (pHoursField
->mFieldName
, "Hours");
868 GetDataType ((CHAR8
*)"UINT8", &pHoursField
->mFieldType
);
869 pHoursField
->mOffset
= 0;
870 pHoursField
->mNext
= pMinutesField
;
871 pHoursField
->mArrayNum
= 0;
872 pHoursField
->mIsBitField
= FALSE
;
874 strcpy (pMinutesField
->mFieldName
, "Minutes");
875 GetDataType ((CHAR8
*)"UINT8", &pMinutesField
->mFieldType
);
876 pMinutesField
->mOffset
= 1;
877 pMinutesField
->mNext
= pSecondsField
;
878 pMinutesField
->mArrayNum
= 0;
879 pMinutesField
->mIsBitField
= FALSE
;
881 strcpy (pSecondsField
->mFieldName
, "Seconds");
882 GetDataType ((CHAR8
*)"UINT8", &pSecondsField
->mFieldType
);
883 pSecondsField
->mOffset
= 2;
884 pSecondsField
->mNext
= NULL
;
885 pSecondsField
->mArrayNum
= 0;
886 pSecondsField
->mIsBitField
= FALSE
;
888 New
->mMembers
= pHoursField
;
889 } else if (strcmp (gInternalTypesTable
[Index
].mTypeName
, "EFI_HII_REF") == 0) {
890 SVfrDataField
*pQuestionIdField
= new SVfrDataField
;
891 SVfrDataField
*pFormIdField
= new SVfrDataField
;
892 SVfrDataField
*pFormSetGuidField
= new SVfrDataField
;
893 SVfrDataField
*pDevicePathField
= new SVfrDataField
;
895 strcpy (pQuestionIdField
->mFieldName
, "QuestionId");
896 GetDataType ((CHAR8
*)"UINT16", &pQuestionIdField
->mFieldType
);
897 pQuestionIdField
->mOffset
= 0;
898 pQuestionIdField
->mNext
= pFormIdField
;
899 pQuestionIdField
->mArrayNum
= 0;
900 pQuestionIdField
->mIsBitField
= FALSE
;
902 strcpy (pFormIdField
->mFieldName
, "FormId");
903 GetDataType ((CHAR8
*)"UINT16", &pFormIdField
->mFieldType
);
904 pFormIdField
->mOffset
= 2;
905 pFormIdField
->mNext
= pFormSetGuidField
;
906 pFormIdField
->mArrayNum
= 0;
907 pFormIdField
->mIsBitField
= FALSE
;
909 strcpy (pFormSetGuidField
->mFieldName
, "FormSetGuid");
910 GetDataType ((CHAR8
*)"EFI_GUID", &pFormSetGuidField
->mFieldType
);
911 pFormSetGuidField
->mOffset
= 4;
912 pFormSetGuidField
->mNext
= pDevicePathField
;
913 pFormSetGuidField
->mArrayNum
= 0;
914 pFormSetGuidField
->mIsBitField
= FALSE
;
916 strcpy (pDevicePathField
->mFieldName
, "DevicePath");
917 GetDataType ((CHAR8
*)"EFI_STRING_ID", &pDevicePathField
->mFieldType
);
918 pDevicePathField
->mOffset
= 20;
919 pDevicePathField
->mNext
= NULL
;
920 pDevicePathField
->mArrayNum
= 0;
921 pDevicePathField
->mIsBitField
= FALSE
;
923 New
->mMembers
= pQuestionIdField
;
925 New
->mMembers
= NULL
;
928 RegisterNewType (New
);
934 CVfrVarDataTypeDB::CVfrVarDataTypeDB (
938 mDataTypeList
= NULL
;
940 mCurrDataField
= NULL
;
941 mPackAlign
= DEFAULT_PACK_ALIGN
;
943 mFirstNewDataTypeName
= NULL
;
944 mCurrDataType
= NULL
;
946 InternalTypesListInit ();
949 CVfrVarDataTypeDB::~CVfrVarDataTypeDB (
954 SVfrDataField
*pField
;
955 SVfrPackStackNode
*pPack
;
957 if (mNewDataType
!= NULL
) {
961 while (mDataTypeList
!= NULL
) {
962 pType
= mDataTypeList
;
963 mDataTypeList
= mDataTypeList
->mNext
;
964 while(pType
->mMembers
!= NULL
) {
965 pField
= pType
->mMembers
;
966 pType
->mMembers
= pType
->mMembers
->mNext
;
972 while (mPackStack
!= NULL
) {
974 mPackStack
= mPackStack
->mNext
;
980 CVfrVarDataTypeDB::Pack (
983 IN CHAR8
*Identifier
,
988 CHAR8 Msg
[MAX_STRING_LEN
] = {0, };
990 if (Action
& VFR_PACK_SHOW
) {
991 sprintf (Msg
, "value of pragma pack(show) == %d", mPackAlign
);
992 gCVfrErrorHandle
.PrintMsg (LineNum
, NULL
, "Warning", Msg
);
995 if (Action
& VFR_PACK_PUSH
) {
996 SVfrPackStackNode
*pNew
= NULL
;
998 if ((pNew
= new SVfrPackStackNode (Identifier
, mPackAlign
)) == NULL
) {
999 return VFR_RETURN_FATAL_ERROR
;
1001 pNew
->mNext
= mPackStack
;
1005 if (Action
& VFR_PACK_POP
) {
1006 SVfrPackStackNode
*pNode
= NULL
;
1008 if (mPackStack
== NULL
) {
1009 gCVfrErrorHandle
.PrintMsg (LineNum
, NULL
, "Error", "#pragma pack(pop...) : more pops than pushes");
1012 for (pNode
= mPackStack
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1013 if (pNode
->Match (Identifier
) == TRUE
) {
1014 mPackAlign
= pNode
->mNumber
;
1015 mPackStack
= pNode
->mNext
;
1020 if (Action
& VFR_PACK_ASSIGN
) {
1021 PackAlign
= (Number
> 1) ? Number
+ Number
% 2 : Number
;
1022 if ((PackAlign
== 0) || (PackAlign
> 16)) {
1023 gCVfrErrorHandle
.PrintMsg (LineNum
, NULL
, "Error", "expected pragma parameter to be '1', '2', '4', '8', or '16'");
1025 mPackAlign
= PackAlign
;
1029 return VFR_RETURN_SUCCESS
;
1033 CVfrVarDataTypeDB::DeclareDataTypeBegin (
1037 SVfrDataType
*pNewType
= NULL
;
1039 pNewType
= new SVfrDataType
;
1040 pNewType
->mTypeName
[0] = '\0';
1041 pNewType
->mType
= EFI_IFR_TYPE_OTHER
;
1042 pNewType
->mAlign
= DEFAULT_ALIGN
;
1043 pNewType
->mTotalSize
= 0;
1044 pNewType
->mMembers
= NULL
;
1045 pNewType
->mNext
= NULL
;
1046 pNewType
->mHasBitField
= FALSE
;
1048 mNewDataType
= pNewType
;
1052 CVfrVarDataTypeDB::SetNewTypeName (
1056 SVfrDataType
*pType
;
1058 if (mNewDataType
== NULL
) {
1059 return VFR_RETURN_ERROR_SKIPED
;
1061 if (TypeName
== NULL
) {
1062 return VFR_RETURN_FATAL_ERROR
;
1064 if (strlen(TypeName
) >= MAX_NAME_LEN
) {
1065 return VFR_RETURN_INVALID_PARAMETER
;
1068 for (pType
= mDataTypeList
; pType
!= NULL
; pType
= pType
->mNext
) {
1069 if (strcmp(pType
->mTypeName
, TypeName
) == 0) {
1070 return VFR_RETURN_REDEFINED
;
1074 strncpy(mNewDataType
->mTypeName
, TypeName
, MAX_NAME_LEN
- 1);
1075 mNewDataType
->mTypeName
[MAX_NAME_LEN
- 1] = 0;
1076 return VFR_RETURN_SUCCESS
;
1080 Record the bit field info in the data type.
1082 @param FieldName Point to the field name.
1083 @param TypeName Point to the type name.
1084 @param Width The bit width.
1085 @param FieldInUnion The filed is in Union type or Structure type.
1089 CVfrVarDataTypeDB::DataTypeAddBitField (
1090 IN CHAR8
*FieldName
,
1093 IN BOOLEAN FieldInUnion
1096 SVfrDataField
*pNewField
= NULL
;
1097 SVfrDataType
*pFieldType
= NULL
;
1098 SVfrDataField
*pTmp
;
1100 UINT32 MaxDataTypeSize
;
1101 BOOLEAN UpdateTotalSize
;
1103 CHECK_ERROR_RETURN (GetDataType (TypeName
, &pFieldType
), VFR_RETURN_SUCCESS
);
1105 if (Width
> MAX_BIT_WIDTH
) {
1106 return VFR_RETURN_BIT_WIDTH_ERROR
;
1109 if (Width
> pFieldType
->mTotalSize
* 8) {
1110 return VFR_RETURN_BIT_WIDTH_ERROR
;
1113 if (FieldName
!= NULL
&& strlen (FieldName
) >= MAX_NAME_LEN
) {
1114 return VFR_RETURN_INVALID_PARAMETER
;
1117 if (Width
== 0 && FieldName
!= NULL
) {
1118 return VFR_RETURN_INVALID_PARAMETER
;
1121 for (pTmp
= mNewDataType
->mMembers
; pTmp
!= NULL
; pTmp
= pTmp
->mNext
) {
1122 if (FieldName
!= NULL
&& strcmp (pTmp
->mFieldName
, FieldName
) == 0) {
1123 return VFR_RETURN_REDEFINED
;
1127 Align
= MIN (mPackAlign
, pFieldType
->mAlign
);
1128 UpdateTotalSize
= FALSE
;
1130 if ((pNewField
= new SVfrDataField
) == NULL
) {
1131 return VFR_RETURN_OUT_FOR_RESOURCES
;
1134 MaxDataTypeSize
= mNewDataType
->mTotalSize
;
1135 if (FieldName
!= NULL
) {
1136 strncpy (pNewField
->mFieldName
, FieldName
, MAX_NAME_LEN
- 1);
1137 pNewField
->mFieldName
[MAX_NAME_LEN
- 1] = 0;
1139 pNewField
->mFieldType
= pFieldType
;
1140 pNewField
->mIsBitField
= TRUE
;
1141 pNewField
->mBitWidth
= Width
;
1142 pNewField
->mArrayNum
= 0;
1143 pNewField
->mBitOffset
= 0;
1144 pNewField
->mOffset
= 0;
1146 if (mNewDataType
->mMembers
== NULL
) {
1147 mNewDataType
->mMembers
= pNewField
;
1148 pNewField
->mNext
= NULL
;
1150 for (pTmp
= mNewDataType
->mMembers
; pTmp
->mNext
!= NULL
; pTmp
= pTmp
->mNext
)
1152 pTmp
->mNext
= pNewField
;
1153 pNewField
->mNext
= NULL
;
1157 pNewField
->mOffset
= 0;
1158 if (MaxDataTypeSize
< pNewField
->mFieldType
->mTotalSize
) {
1159 mNewDataType
->mTotalSize
= pNewField
->mFieldType
->mTotalSize
;
1163 // Check whether the bit fields can be contained within one FieldType.
1165 if (pTmp
!= NULL
&& pTmp
->mIsBitField
&& strcmp (pTmp
->mFieldType
->mTypeName
, pNewField
->mFieldType
->mTypeName
) == 0 &&
1166 (pTmp
->mBitOffset
- pTmp
->mOffset
* 8) + pTmp
->mBitWidth
+ pNewField
->mBitWidth
<= pNewField
->mFieldType
->mTotalSize
* 8) {
1167 pNewField
->mBitOffset
= pTmp
->mBitOffset
+ pTmp
->mBitWidth
;
1168 pNewField
->mOffset
= pTmp
->mOffset
;
1170 // If BitWidth=0,used to force alignment at the next word boundary.
1171 // So make this bit field occupy the remaing bit width of current field type.
1173 if (pNewField
->mBitWidth
== 0) {
1174 pNewField
->mBitWidth
= pNewField
->mFieldType
->mTotalSize
* 8 - (pNewField
->mBitOffset
- pTmp
->mOffset
* 8);
1178 // The bit filed start a new memory
1180 pNewField
->mBitOffset
= mNewDataType
->mTotalSize
* 8;
1181 UpdateTotalSize
= TRUE
;
1185 if (UpdateTotalSize
){
1186 if ((mNewDataType
->mTotalSize
% Align
) == 0) {
1187 pNewField
->mOffset
= mNewDataType
->mTotalSize
;
1189 pNewField
->mOffset
= mNewDataType
->mTotalSize
+ ALIGN_STUFF(mNewDataType
->mTotalSize
, Align
);
1191 mNewDataType
->mTotalSize
= pNewField
->mOffset
+ (pNewField
->mFieldType
->mTotalSize
);
1194 mNewDataType
->mAlign
= MIN (mPackAlign
, MAX (pFieldType
->mAlign
, mNewDataType
->mAlign
));
1195 mNewDataType
->mHasBitField
= TRUE
;
1196 return VFR_RETURN_SUCCESS
;
1200 CVfrVarDataTypeDB::DataTypeAddField (
1201 IN CHAR8
*FieldName
,
1204 IN BOOLEAN FieldInUnion
1207 SVfrDataField
*pNewField
= NULL
;
1208 SVfrDataType
*pFieldType
= NULL
;
1209 SVfrDataField
*pTmp
;
1211 UINT32 MaxDataTypeSize
;
1213 CHECK_ERROR_RETURN (GetDataType (TypeName
, &pFieldType
), VFR_RETURN_SUCCESS
);
1214 MaxDataTypeSize
= mNewDataType
->mTotalSize
;
1216 if (strlen (FieldName
) >= MAX_NAME_LEN
) {
1217 return VFR_RETURN_INVALID_PARAMETER
;
1220 for (pTmp
= mNewDataType
->mMembers
; pTmp
!= NULL
; pTmp
= pTmp
->mNext
) {
1221 if (strcmp (pTmp
->mFieldName
, FieldName
) == 0) {
1222 return VFR_RETURN_REDEFINED
;
1226 Align
= MIN (mPackAlign
, pFieldType
->mAlign
);
1228 if ((pNewField
= new SVfrDataField
) == NULL
) {
1229 return VFR_RETURN_OUT_FOR_RESOURCES
;
1231 strncpy (pNewField
->mFieldName
, FieldName
, MAX_NAME_LEN
- 1);
1232 pNewField
->mFieldName
[MAX_NAME_LEN
- 1] = 0;
1233 pNewField
->mFieldType
= pFieldType
;
1234 pNewField
->mArrayNum
= ArrayNum
;
1235 pNewField
->mIsBitField
= FALSE
;
1236 if ((mNewDataType
->mTotalSize
% Align
) == 0) {
1237 pNewField
->mOffset
= mNewDataType
->mTotalSize
;
1239 pNewField
->mOffset
= mNewDataType
->mTotalSize
+ ALIGN_STUFF(mNewDataType
->mTotalSize
, Align
);
1241 if (mNewDataType
->mMembers
== NULL
) {
1242 mNewDataType
->mMembers
= pNewField
;
1243 pNewField
->mNext
= NULL
;
1245 for (pTmp
= mNewDataType
->mMembers
; pTmp
->mNext
!= NULL
; pTmp
= pTmp
->mNext
)
1247 pTmp
->mNext
= pNewField
;
1248 pNewField
->mNext
= NULL
;
1251 mNewDataType
->mAlign
= MIN (mPackAlign
, MAX (pFieldType
->mAlign
, mNewDataType
->mAlign
));
1254 if (MaxDataTypeSize
< pNewField
->mFieldType
->mTotalSize
) {
1255 mNewDataType
->mTotalSize
= pNewField
->mFieldType
->mTotalSize
;
1257 pNewField
->mOffset
= 0;
1259 mNewDataType
->mTotalSize
= pNewField
->mOffset
+ (pNewField
->mFieldType
->mTotalSize
) * ((ArrayNum
== 0) ? 1 : ArrayNum
);
1262 return VFR_RETURN_SUCCESS
;
1266 CVfrVarDataTypeDB::DeclareDataTypeEnd (
1270 if (mNewDataType
->mTypeName
[0] == '\0') {
1274 if ((mNewDataType
->mTotalSize
% mNewDataType
->mAlign
) !=0) {
1275 mNewDataType
->mTotalSize
+= ALIGN_STUFF (mNewDataType
->mTotalSize
, mNewDataType
->mAlign
);
1278 RegisterNewType (mNewDataType
);
1279 if (mFirstNewDataTypeName
== NULL
) {
1280 mFirstNewDataTypeName
= mNewDataType
->mTypeName
;
1283 mNewDataType
= NULL
;
1287 CVfrVarDataTypeDB::GetDataType (
1289 OUT SVfrDataType
**DataType
1292 SVfrDataType
*pDataType
= NULL
;
1294 if (TypeName
== NULL
) {
1295 return VFR_RETURN_ERROR_SKIPED
;
1298 if (DataType
== NULL
) {
1299 return VFR_RETURN_FATAL_ERROR
;
1304 for (pDataType
= mDataTypeList
; pDataType
!= NULL
; pDataType
= pDataType
->mNext
) {
1305 if (strcmp (TypeName
, pDataType
->mTypeName
) == 0) {
1306 *DataType
= pDataType
;
1307 return VFR_RETURN_SUCCESS
;
1311 return VFR_RETURN_UNDEFINED
;
1315 CVfrVarDataTypeDB::GetDataTypeSize (
1320 SVfrDataType
*pDataType
= NULL
;
1323 return VFR_RETURN_FATAL_ERROR
;
1327 DataType
= DataType
& 0x0F;
1330 // For user defined data type, the size can't be got by this function.
1332 if (DataType
== EFI_IFR_TYPE_OTHER
) {
1333 return VFR_RETURN_SUCCESS
;
1336 for (pDataType
= mDataTypeList
; pDataType
!= NULL
; pDataType
= pDataType
->mNext
) {
1337 if (DataType
== pDataType
->mType
) {
1338 *Size
= pDataType
->mTotalSize
;
1339 return VFR_RETURN_SUCCESS
;
1343 return VFR_RETURN_UNDEFINED
;
1347 CVfrVarDataTypeDB::GetDataTypeSize (
1352 SVfrDataType
*pDataType
= NULL
;
1355 return VFR_RETURN_FATAL_ERROR
;
1360 for (pDataType
= mDataTypeList
; pDataType
!= NULL
; pDataType
= pDataType
->mNext
) {
1361 if (strcmp (TypeName
, pDataType
->mTypeName
) == 0) {
1362 *Size
= pDataType
->mTotalSize
;
1363 return VFR_RETURN_SUCCESS
;
1367 return VFR_RETURN_UNDEFINED
;
1371 CVfrVarDataTypeDB::GetDataFieldInfo (
1376 OUT BOOLEAN
&BitField
1379 CHAR8 TName
[MAX_NAME_LEN
], FName
[MAX_NAME_LEN
];
1380 UINT32 ArrayIdx
, Tmp
;
1381 SVfrDataType
*pType
= NULL
;
1382 SVfrDataField
*pField
= NULL
;
1386 Type
= EFI_IFR_TYPE_OTHER
;
1388 VarStrName
= VarStr
;
1390 CHECK_ERROR_RETURN (ExtractStructTypeName (VarStr
, TName
), VFR_RETURN_SUCCESS
);
1391 CHECK_ERROR_RETURN (GetDataType (TName
, &pType
), VFR_RETURN_SUCCESS
);
1393 BitField
= IsThisBitField (VarStrName
);
1396 // if it is not struct data type
1398 Type
= pType
->mType
;
1399 Size
= pType
->mTotalSize
;
1401 while (*VarStr
!= '\0') {
1402 CHECK_ERROR_RETURN(ExtractFieldNameAndArrary(VarStr
, FName
, ArrayIdx
), VFR_RETURN_SUCCESS
);
1403 CHECK_ERROR_RETURN(GetTypeField (FName
, pType
, pField
), VFR_RETURN_SUCCESS
);
1404 pType
= pField
->mFieldType
;
1405 CHECK_ERROR_RETURN(GetFieldOffset (pField
, ArrayIdx
, Tmp
, pField
->mIsBitField
), VFR_RETURN_SUCCESS
);
1406 if (BitField
&& !pField
->mIsBitField
) {
1407 Offset
= (UINT16
) (Offset
+ Tmp
* 8);
1409 Offset
= (UINT16
) (Offset
+ Tmp
);
1411 Type
= GetFieldWidth (pField
);
1412 Size
= GetFieldSize (pField
, ArrayIdx
, BitField
);
1414 return VFR_RETURN_SUCCESS
;
1418 CVfrVarDataTypeDB::GetUserDefinedTypeNameList (
1419 OUT CHAR8
***NameList
,
1420 OUT UINT32
*ListSize
1424 SVfrDataType
*pType
;
1426 if ((NameList
== NULL
) || (ListSize
== NULL
)) {
1427 return VFR_RETURN_FATAL_ERROR
;
1433 for (pType
= mDataTypeList
; pType
!= NULL
; pType
= pType
->mNext
) {
1434 if (_IS_INTERNAL_TYPE(pType
->mTypeName
) == FALSE
) {
1439 if (*ListSize
== 0) {
1440 return VFR_RETURN_SUCCESS
;
1443 if ((*NameList
= new CHAR8
*[*ListSize
]) == NULL
) {
1445 return VFR_RETURN_OUT_FOR_RESOURCES
;
1448 for (Index
= 0, pType
= mDataTypeList
; pType
!= NULL
; pType
= pType
->mNext
, Index
++) {
1449 if (_IS_INTERNAL_TYPE(pType
->mTypeName
) == FALSE
) {
1450 (*NameList
)[Index
] = pType
->mTypeName
;
1453 return VFR_RETURN_SUCCESS
;
1457 CVfrVarDataTypeDB::IsTypeNameDefined (
1461 SVfrDataType
*pType
;
1463 if (TypeName
== NULL
) {
1467 for (pType
= mDataTypeList
; pType
!= NULL
; pType
= pType
->mNext
) {
1468 if (strcmp (pType
->mTypeName
, TypeName
) == 0) {
1477 CVfrVarDataTypeDB::Dump (
1481 SVfrDataType
*pTNode
;
1482 SVfrDataField
*pFNode
;
1484 fprintf (File
, "\n\n***************************************************************\n");
1485 fprintf (File
, "\t\tmPackAlign = %x\n", mPackAlign
);
1486 for (pTNode
= mDataTypeList
; pTNode
!= NULL
; pTNode
= pTNode
->mNext
) {
1487 fprintf (File
, "\t\tstruct %s : mAlign [%d] mTotalSize [0x%x]\n\n", pTNode
->mTypeName
, pTNode
->mAlign
, pTNode
->mTotalSize
);
1488 fprintf (File
, "\t\tstruct %s {\n", pTNode
->mTypeName
);
1489 for (pFNode
= pTNode
->mMembers
; pFNode
!= NULL
; pFNode
= pFNode
->mNext
) {
1490 if (pFNode
->mArrayNum
> 0) {
1491 fprintf (File
, "\t\t\t+%08d[%08x] %s[%d] <%s>\n", pFNode
->mOffset
, pFNode
->mOffset
,
1492 pFNode
->mFieldName
, pFNode
->mArrayNum
, pFNode
->mFieldType
->mTypeName
);
1494 fprintf (File
, "\t\t\t+%08d[%08x] %s <%s>\n", pFNode
->mOffset
, pFNode
->mOffset
,
1495 pFNode
->mFieldName
, pFNode
->mFieldType
->mTypeName
);
1498 fprintf (File
, "\t\t};\n");
1499 fprintf (File
, "---------------------------------------------------------------\n");
1501 fprintf (File
, "***************************************************************\n");
1504 #ifdef CVFR_VARDATATYPEDB_DEBUG
1506 CVfrVarDataTypeDB::ParserDB (
1510 SVfrDataType
*pTNode
;
1511 SVfrDataField
*pFNode
;
1513 printf ("***************************************************************\n");
1514 printf ("\t\tmPackAlign = %x\n", mPackAlign
);
1515 for (pTNode
= mDataTypeList
; pTNode
!= NULL
; pTNode
= pTNode
->mNext
) {
1516 printf ("\t\tstruct %s : mAlign [%x] mTotalSize [%x]\n\n", pTNode
->mTypeName
, pTNode
->mAlign
, pTNode
->mTotalSize
);
1517 printf ("\t\tstruct %s {\n", pTNode
->mTypeName
);
1518 for (pFNode
= pTNode
->mMembers
; pFNode
!= NULL
; pFNode
= pFNode
->mNext
) {
1519 printf ("\t\t\t%s\t%s\n", pFNode
->mFieldType
->mTypeName
, pFNode
->mFieldName
);
1521 printf ("\t\t};\n");
1522 printf ("---------------------------------------------------------------\n");
1524 printf ("***************************************************************\n");
1528 SVfrVarStorageNode::SVfrVarStorageNode (
1530 IN CHAR8
*StoreName
,
1531 IN EFI_VARSTORE_ID VarStoreId
,
1532 IN EFI_STRING_ID VarName
,
1540 memset (&mGuid
, 0, sizeof (EFI_GUID
));
1542 if (StoreName
!= NULL
) {
1543 mVarStoreName
= new CHAR8
[strlen(StoreName
) + 1];
1544 strcpy (mVarStoreName
, StoreName
);
1546 mVarStoreName
= NULL
;
1549 mVarStoreId
= VarStoreId
;
1550 mVarStoreType
= EFI_VFR_VARSTORE_EFI
;
1551 mStorageInfo
.mEfiVar
.mEfiVarName
= VarName
;
1552 mStorageInfo
.mEfiVar
.mEfiVarSize
= VarSize
;
1553 mAssignedFlag
= Flag
;
1556 SVfrVarStorageNode::SVfrVarStorageNode (
1558 IN CHAR8
*StoreName
,
1559 IN EFI_VARSTORE_ID VarStoreId
,
1560 IN SVfrDataType
*DataType
,
1561 IN BOOLEAN BitsVarstore
,
1568 memset (&mGuid
, 0, sizeof (EFI_GUID
));
1570 if (StoreName
!= NULL
) {
1571 mVarStoreName
= new CHAR8
[strlen(StoreName
) + 1];
1572 strcpy (mVarStoreName
, StoreName
);
1574 mVarStoreName
= NULL
;
1577 mVarStoreId
= VarStoreId
;
1579 mVarStoreType
= EFI_VFR_VARSTORE_BUFFER_BITS
;
1581 mVarStoreType
= EFI_VFR_VARSTORE_BUFFER
;
1583 mStorageInfo
.mDataType
= DataType
;
1584 mAssignedFlag
= Flag
;
1587 SVfrVarStorageNode::SVfrVarStorageNode (
1588 IN CHAR8
*StoreName
,
1589 IN EFI_VARSTORE_ID VarStoreId
1592 memset (&mGuid
, 0, sizeof (EFI_GUID
));
1593 if (StoreName
!= NULL
) {
1594 mVarStoreName
= new CHAR8
[strlen(StoreName
) + 1];
1595 strcpy (mVarStoreName
, StoreName
);
1597 mVarStoreName
= NULL
;
1600 mVarStoreId
= VarStoreId
;
1601 mVarStoreType
= EFI_VFR_VARSTORE_NAME
;
1602 mStorageInfo
.mNameSpace
.mNameTable
= new EFI_VARSTORE_ID
[DEFAULT_NAME_TABLE_ITEMS
];
1603 mStorageInfo
.mNameSpace
.mTableSize
= 0;
1604 mAssignedFlag
= FALSE
;
1607 SVfrVarStorageNode::~SVfrVarStorageNode (
1611 if (mVarStoreName
!= NULL
) {
1612 delete[] mVarStoreName
;
1615 if (mVarStoreType
== EFI_VFR_VARSTORE_NAME
) {
1616 delete[] mStorageInfo
.mNameSpace
.mNameTable
;
1620 CVfrDataStorage::CVfrDataStorage (
1626 for (Index
= 0; Index
< EFI_FREE_VARSTORE_ID_BITMAP_SIZE
; Index
++) {
1627 mFreeVarStoreIdBitMap
[Index
] = 0;
1630 // Question ID 0 is reserved.
1631 mFreeVarStoreIdBitMap
[0] = 0x80000000;
1633 mBufferVarStoreList
= NULL
;
1634 mEfiVarStoreList
= NULL
;
1635 mNameVarStoreList
= NULL
;
1636 mCurrVarStorageNode
= NULL
;
1637 mNewVarStorageNode
= NULL
;
1638 mBufferFieldInfoListHead
= NULL
;
1639 mBufferFieldInfoListTail
= NULL
;
1642 CVfrDataStorage::~CVfrDataStorage (
1646 SVfrVarStorageNode
*pNode
;
1648 while (mBufferVarStoreList
!= NULL
) {
1649 pNode
= mBufferVarStoreList
;
1650 mBufferVarStoreList
= mBufferVarStoreList
->mNext
;
1653 while (mEfiVarStoreList
!= NULL
) {
1654 pNode
= mEfiVarStoreList
;
1655 mEfiVarStoreList
= mEfiVarStoreList
->mNext
;
1658 while (mNameVarStoreList
!= NULL
) {
1659 pNode
= mNameVarStoreList
;
1660 mNameVarStoreList
= mNameVarStoreList
->mNext
;
1663 if (mNewVarStorageNode
!= NULL
) {
1664 delete mNewVarStorageNode
;
1669 CVfrDataStorage::GetFreeVarStoreId (
1670 EFI_VFR_VARSTORE_TYPE VarType
1673 UINT32 Index
, Mask
, Offset
;
1677 for (; Index
< EFI_FREE_VARSTORE_ID_BITMAP_SIZE
; Index
++) {
1678 if (mFreeVarStoreIdBitMap
[Index
] != 0xFFFFFFFF) {
1683 if (Index
== EFI_FREE_VARSTORE_ID_BITMAP_SIZE
) {
1684 return EFI_VARSTORE_ID_INVALID
;
1687 for (Offset
= 0, Mask
= 0x80000000; Mask
!= 0; Mask
>>= 1, Offset
++) {
1688 if ((mFreeVarStoreIdBitMap
[Index
] & Mask
) == 0) {
1689 mFreeVarStoreIdBitMap
[Index
] |= Mask
;
1690 return (EFI_VARSTORE_ID
)((Index
<< EFI_BITS_SHIFT_PER_UINT32
) + Offset
);
1694 return EFI_VARSTORE_ID_INVALID
;
1698 CVfrDataStorage::ChekVarStoreIdFree (
1699 IN EFI_VARSTORE_ID VarStoreId
1702 UINT32 Index
= (VarStoreId
/ EFI_BITS_PER_UINT32
);
1703 UINT32 Offset
= (VarStoreId
% EFI_BITS_PER_UINT32
);
1705 return (mFreeVarStoreIdBitMap
[Index
] & (0x80000000 >> Offset
)) == 0;
1709 CVfrDataStorage::MarkVarStoreIdUsed (
1710 IN EFI_VARSTORE_ID VarStoreId
1713 UINT32 Index
= (VarStoreId
/ EFI_BITS_PER_UINT32
);
1714 UINT32 Offset
= (VarStoreId
% EFI_BITS_PER_UINT32
);
1716 mFreeVarStoreIdBitMap
[Index
] |= (0x80000000 >> Offset
);
1720 CVfrDataStorage::MarkVarStoreIdUnused (
1721 IN EFI_VARSTORE_ID VarStoreId
1724 UINT32 Index
= (VarStoreId
/ EFI_BITS_PER_UINT32
);
1725 UINT32 Offset
= (VarStoreId
% EFI_BITS_PER_UINT32
);
1727 mFreeVarStoreIdBitMap
[Index
] &= ~(0x80000000 >> Offset
);
1731 CVfrDataStorage::DeclareNameVarStoreBegin (
1732 IN CHAR8
*StoreName
,
1733 IN EFI_VARSTORE_ID VarStoreId
1736 SVfrVarStorageNode
*pNode
= NULL
;
1737 EFI_VARSTORE_ID TmpVarStoreId
;
1739 if (StoreName
== NULL
) {
1740 return VFR_RETURN_FATAL_ERROR
;
1743 if (GetVarStoreId (StoreName
, &TmpVarStoreId
) == VFR_RETURN_SUCCESS
) {
1744 return VFR_RETURN_REDEFINED
;
1747 if (VarStoreId
== EFI_VARSTORE_ID_INVALID
) {
1748 VarStoreId
= GetFreeVarStoreId (EFI_VFR_VARSTORE_NAME
);
1750 if (ChekVarStoreIdFree (VarStoreId
) == FALSE
) {
1751 return VFR_RETURN_VARSTOREID_REDEFINED
;
1753 MarkVarStoreIdUsed (VarStoreId
);
1756 if ((pNode
= new SVfrVarStorageNode (StoreName
, VarStoreId
)) == NULL
) {
1757 return VFR_RETURN_UNDEFINED
;
1760 mNewVarStorageNode
= pNode
;
1762 return VFR_RETURN_SUCCESS
;
1766 CVfrDataStorage::NameTableAddItem (
1767 IN EFI_STRING_ID Item
1770 EFI_VARSTORE_ID
*NewTable
, *OldTable
;
1773 OldTable
= mNewVarStorageNode
->mStorageInfo
.mNameSpace
.mNameTable
;
1774 TableSize
= mNewVarStorageNode
->mStorageInfo
.mNameSpace
.mTableSize
;
1776 if ((TableSize
!= 0) && ((TableSize
% DEFAULT_NAME_TABLE_ITEMS
) == 0)) {
1777 if ((NewTable
= new EFI_VARSTORE_ID
[TableSize
+ DEFAULT_NAME_TABLE_ITEMS
]) == NULL
) {
1778 return VFR_RETURN_OUT_FOR_RESOURCES
;
1780 memcpy (NewTable
, OldTable
, TableSize
);
1781 mNewVarStorageNode
->mStorageInfo
.mNameSpace
.mNameTable
= NewTable
;
1784 mNewVarStorageNode
->mStorageInfo
.mNameSpace
.mNameTable
[TableSize
++] = Item
;
1785 mNewVarStorageNode
->mStorageInfo
.mNameSpace
.mTableSize
= TableSize
;
1787 return VFR_RETURN_SUCCESS
;
1791 CVfrDataStorage::DeclareNameVarStoreEnd (
1795 mNewVarStorageNode
->mGuid
= *Guid
;
1796 mNewVarStorageNode
->mNext
= mNameVarStoreList
;
1797 mNameVarStoreList
= mNewVarStorageNode
;
1799 mNewVarStorageNode
= NULL
;
1801 return VFR_RETURN_SUCCESS
;
1805 CVfrDataStorage::DeclareEfiVarStore (
1806 IN CHAR8
*StoreName
,
1808 IN EFI_STRING_ID NameStrId
,
1813 SVfrVarStorageNode
*pNode
;
1814 EFI_VARSTORE_ID VarStoreId
;
1816 if ((StoreName
== NULL
) || (Guid
== NULL
)) {
1817 return VFR_RETURN_FATAL_ERROR
;
1820 if (VarSize
> sizeof (UINT64
)) {
1821 return VFR_RETURN_EFIVARSTORE_SIZE_ERROR
;
1824 if (GetVarStoreId (StoreName
, &VarStoreId
, Guid
) == VFR_RETURN_SUCCESS
) {
1825 return VFR_RETURN_REDEFINED
;
1828 VarStoreId
= GetFreeVarStoreId (EFI_VFR_VARSTORE_EFI
);
1829 if ((pNode
= new SVfrVarStorageNode (Guid
, StoreName
, VarStoreId
, NameStrId
, VarSize
, Flag
)) == NULL
) {
1830 return VFR_RETURN_OUT_FOR_RESOURCES
;
1833 pNode
->mNext
= mEfiVarStoreList
;
1834 mEfiVarStoreList
= pNode
;
1836 return VFR_RETURN_SUCCESS
;
1840 CVfrDataStorage::DeclareBufferVarStore (
1841 IN CHAR8
*StoreName
,
1843 IN CVfrVarDataTypeDB
*DataTypeDB
,
1845 IN EFI_VARSTORE_ID VarStoreId
,
1846 IN BOOLEAN IsBitVarStore
,
1850 SVfrVarStorageNode
*pNew
= NULL
;
1851 SVfrDataType
*pDataType
= NULL
;
1852 EFI_VARSTORE_ID TempVarStoreId
;
1854 if ((StoreName
== NULL
) || (Guid
== NULL
) || (DataTypeDB
== NULL
)) {
1855 return VFR_RETURN_FATAL_ERROR
;
1858 if (GetVarStoreId (StoreName
, &TempVarStoreId
, Guid
) == VFR_RETURN_SUCCESS
) {
1859 return VFR_RETURN_REDEFINED
;
1862 CHECK_ERROR_RETURN(DataTypeDB
->GetDataType (TypeName
, &pDataType
), VFR_RETURN_SUCCESS
);
1864 if (VarStoreId
== EFI_VARSTORE_ID_INVALID
) {
1865 VarStoreId
= GetFreeVarStoreId (EFI_VFR_VARSTORE_BUFFER
);
1867 if (ChekVarStoreIdFree (VarStoreId
) == FALSE
) {
1868 return VFR_RETURN_VARSTOREID_REDEFINED
;
1870 MarkVarStoreIdUsed (VarStoreId
);
1873 if ((pNew
= new SVfrVarStorageNode (Guid
, StoreName
, VarStoreId
, pDataType
, IsBitVarStore
, Flag
)) == NULL
) {
1874 return VFR_RETURN_OUT_FOR_RESOURCES
;
1877 pNew
->mNext
= mBufferVarStoreList
;
1878 mBufferVarStoreList
= pNew
;
1880 if (gCVfrBufferConfig
.Register(StoreName
, Guid
) != 0) {
1881 return VFR_RETURN_FATAL_ERROR
;
1884 return VFR_RETURN_SUCCESS
;
1888 CVfrDataStorage::GetVarStoreByDataType (
1889 IN CHAR8
*DataTypeName
,
1890 OUT SVfrVarStorageNode
**VarNode
,
1891 IN EFI_GUID
*VarGuid
1894 SVfrVarStorageNode
*pNode
;
1895 SVfrVarStorageNode
*MatchNode
;
1898 for (pNode
= mBufferVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1899 if (strcmp (pNode
->mStorageInfo
.mDataType
->mTypeName
, DataTypeName
) != 0) {
1903 if ((VarGuid
!= NULL
)) {
1904 if (memcmp (VarGuid
, &pNode
->mGuid
, sizeof (EFI_GUID
)) == 0) {
1906 return VFR_RETURN_SUCCESS
;
1909 if (MatchNode
== NULL
) {
1913 // More than one varstores referred the same data structures.
1915 return VFR_RETURN_VARSTORE_DATATYPE_REDEFINED_ERROR
;
1920 if (MatchNode
== NULL
) {
1921 return VFR_RETURN_UNDEFINED
;
1924 *VarNode
= MatchNode
;
1925 return VFR_RETURN_SUCCESS
;
1929 CVfrDataStorage::CheckGuidField (
1930 IN SVfrVarStorageNode
*pNode
,
1931 IN EFI_GUID
*StoreGuid
,
1932 IN BOOLEAN
*HasFoundOne
,
1933 OUT EFI_VFR_RETURN_CODE
*ReturnCode
1936 if (StoreGuid
!= NULL
) {
1938 // If has guid info, compare the guid filed.
1940 if (memcmp (StoreGuid
, &pNode
->mGuid
, sizeof (EFI_GUID
)) == 0) {
1942 // Both name and guid are same, this this varstore.
1944 mCurrVarStorageNode
= pNode
;
1945 *ReturnCode
= VFR_RETURN_SUCCESS
;
1950 // Not has Guid field, check whether this name is the only one.
1954 // The name has conflict, return name redefined.
1956 *ReturnCode
= VFR_RETURN_VARSTORE_NAME_REDEFINED_ERROR
;
1960 *HasFoundOne
= TRUE
;
1961 mCurrVarStorageNode
= pNode
;
1968 Base on the input store name and guid to find the varstore id.
1970 If both name and guid are inputed, base on the name and guid to
1971 found the varstore. If only name inputed, base on the name to
1972 found the varstore and go on to check whether more than one varstore
1973 has the same name. If only has found one varstore, return this
1974 varstore; if more than one varstore has same name, return varstore
1975 name redefined error. If no varstore found by varstore name, call
1976 function GetVarStoreByDataType and use inputed varstore name as
1977 data type name to search.
1980 CVfrDataStorage::GetVarStoreId (
1981 IN CHAR8
*StoreName
,
1982 OUT EFI_VARSTORE_ID
*VarStoreId
,
1983 IN EFI_GUID
*StoreGuid
1986 EFI_VFR_RETURN_CODE ReturnCode
;
1987 SVfrVarStorageNode
*pNode
;
1988 BOOLEAN HasFoundOne
= FALSE
;
1990 mCurrVarStorageNode
= NULL
;
1992 for (pNode
= mBufferVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1993 if (strcmp (pNode
->mVarStoreName
, StoreName
) == 0) {
1994 if (CheckGuidField(pNode
, StoreGuid
, &HasFoundOne
, &ReturnCode
)) {
1995 *VarStoreId
= mCurrVarStorageNode
->mVarStoreId
;
2001 for (pNode
= mEfiVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2002 if (strcmp (pNode
->mVarStoreName
, StoreName
) == 0) {
2003 if (CheckGuidField(pNode
, StoreGuid
, &HasFoundOne
, &ReturnCode
)) {
2004 *VarStoreId
= mCurrVarStorageNode
->mVarStoreId
;
2010 for (pNode
= mNameVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2011 if (strcmp (pNode
->mVarStoreName
, StoreName
) == 0) {
2012 if (CheckGuidField(pNode
, StoreGuid
, &HasFoundOne
, &ReturnCode
)) {
2013 *VarStoreId
= mCurrVarStorageNode
->mVarStoreId
;
2020 *VarStoreId
= mCurrVarStorageNode
->mVarStoreId
;
2021 return VFR_RETURN_SUCCESS
;
2024 *VarStoreId
= EFI_VARSTORE_ID_INVALID
;
2027 // Assume that Data structure name is used as StoreName, and check again.
2029 ReturnCode
= GetVarStoreByDataType (StoreName
, &pNode
, StoreGuid
);
2030 if (pNode
!= NULL
) {
2031 mCurrVarStorageNode
= pNode
;
2032 *VarStoreId
= pNode
->mVarStoreId
;
2039 CVfrDataStorage::GetBufferVarStoreDataTypeName (
2040 IN EFI_VARSTORE_ID VarStoreId
,
2041 OUT CHAR8
**DataTypeName
2044 SVfrVarStorageNode
*pNode
;
2046 if (VarStoreId
== EFI_VARSTORE_ID_INVALID
) {
2047 return VFR_RETURN_FATAL_ERROR
;
2050 for (pNode
= mBufferVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2051 if (pNode
->mVarStoreId
== VarStoreId
) {
2052 *DataTypeName
= pNode
->mStorageInfo
.mDataType
->mTypeName
;
2053 return VFR_RETURN_SUCCESS
;
2057 return VFR_RETURN_UNDEFINED
;
2060 EFI_VFR_VARSTORE_TYPE
2061 CVfrDataStorage::GetVarStoreType (
2062 IN EFI_VARSTORE_ID VarStoreId
2065 SVfrVarStorageNode
*pNode
;
2066 EFI_VFR_VARSTORE_TYPE VarStoreType
;
2068 VarStoreType
= EFI_VFR_VARSTORE_INVALID
;
2070 if (VarStoreId
== EFI_VARSTORE_ID_INVALID
) {
2071 return VarStoreType
;
2074 for (pNode
= mBufferVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2075 if (pNode
->mVarStoreId
== VarStoreId
) {
2076 VarStoreType
= pNode
->mVarStoreType
;
2077 return VarStoreType
;
2081 for (pNode
= mEfiVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2082 if (pNode
->mVarStoreId
== VarStoreId
) {
2083 VarStoreType
= pNode
->mVarStoreType
;
2084 return VarStoreType
;
2088 for (pNode
= mNameVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2089 if (pNode
->mVarStoreId
== VarStoreId
) {
2090 VarStoreType
= pNode
->mVarStoreType
;
2091 return VarStoreType
;
2095 return VarStoreType
;
2099 CVfrDataStorage::GetVarStoreGuid (
2100 IN EFI_VARSTORE_ID VarStoreId
2103 SVfrVarStorageNode
*pNode
;
2108 if (VarStoreId
== EFI_VARSTORE_ID_INVALID
) {
2112 for (pNode
= mBufferVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2113 if (pNode
->mVarStoreId
== VarStoreId
) {
2114 VarGuid
= &pNode
->mGuid
;
2119 for (pNode
= mEfiVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2120 if (pNode
->mVarStoreId
== VarStoreId
) {
2121 VarGuid
= &pNode
->mGuid
;
2126 for (pNode
= mNameVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2127 if (pNode
->mVarStoreId
== VarStoreId
) {
2128 VarGuid
= &pNode
->mGuid
;
2137 CVfrDataStorage::GetVarStoreName (
2138 IN EFI_VARSTORE_ID VarStoreId
,
2139 OUT CHAR8
**VarStoreName
2142 SVfrVarStorageNode
*pNode
;
2144 if (VarStoreName
== NULL
) {
2145 return VFR_RETURN_FATAL_ERROR
;
2148 for (pNode
= mBufferVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2149 if (pNode
->mVarStoreId
== VarStoreId
) {
2150 *VarStoreName
= pNode
->mVarStoreName
;
2151 return VFR_RETURN_SUCCESS
;
2155 for (pNode
= mEfiVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2156 if (pNode
->mVarStoreId
== VarStoreId
) {
2157 *VarStoreName
= pNode
->mVarStoreName
;
2158 return VFR_RETURN_SUCCESS
;
2162 for (pNode
= mNameVarStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2163 if (pNode
->mVarStoreId
== VarStoreId
) {
2164 *VarStoreName
= pNode
->mVarStoreName
;
2165 return VFR_RETURN_SUCCESS
;
2169 *VarStoreName
= NULL
;
2170 return VFR_RETURN_UNDEFINED
;
2174 CVfrDataStorage::GetEfiVarStoreInfo (
2175 IN OUT EFI_VARSTORE_INFO
*Info
2179 return VFR_RETURN_FATAL_ERROR
;
2182 if (mCurrVarStorageNode
== NULL
) {
2183 return VFR_RETURN_GET_EFIVARSTORE_ERROR
;
2186 Info
->mInfo
.mVarName
= mCurrVarStorageNode
->mStorageInfo
.mEfiVar
.mEfiVarName
;
2187 Info
->mVarTotalSize
= mCurrVarStorageNode
->mStorageInfo
.mEfiVar
.mEfiVarSize
;
2188 switch (Info
->mVarTotalSize
) {
2190 Info
->mVarType
= EFI_IFR_TYPE_NUM_SIZE_8
;
2193 Info
->mVarType
= EFI_IFR_TYPE_NUM_SIZE_16
;
2196 Info
->mVarType
= EFI_IFR_TYPE_NUM_SIZE_32
;
2199 Info
->mVarType
= EFI_IFR_TYPE_NUM_SIZE_64
;
2202 return VFR_RETURN_FATAL_ERROR
;
2205 return VFR_RETURN_SUCCESS
;
2209 CVfrDataStorage::AddBufferVarStoreFieldInfo (
2210 IN EFI_VARSTORE_INFO
*Info
2213 BufferVarStoreFieldInfoNode
*pNew
;
2215 if ((pNew
= new BufferVarStoreFieldInfoNode(Info
)) == NULL
) {
2216 return VFR_RETURN_FATAL_ERROR
;
2219 if (mBufferFieldInfoListHead
== NULL
) {
2220 mBufferFieldInfoListHead
= pNew
;
2221 mBufferFieldInfoListTail
= pNew
;
2223 mBufferFieldInfoListTail
->mNext
= pNew
;
2224 mBufferFieldInfoListTail
= pNew
;
2227 return VFR_RETURN_SUCCESS
;
2231 CVfrDataStorage::GetBufferVarStoreFieldInfo (
2232 IN OUT EFI_VARSTORE_INFO
*Info
2235 BufferVarStoreFieldInfoNode
*pNode
;
2237 pNode
= mBufferFieldInfoListHead
;
2238 while (pNode
!= NULL
) {
2239 if (Info
->mVarStoreId
== pNode
->mVarStoreInfo
.mVarStoreId
&&
2240 Info
->mInfo
.mVarOffset
== pNode
->mVarStoreInfo
.mInfo
.mVarOffset
) {
2241 Info
->mVarTotalSize
= pNode
->mVarStoreInfo
.mVarTotalSize
;
2242 Info
->mVarType
= pNode
->mVarStoreInfo
.mVarType
;
2243 return VFR_RETURN_SUCCESS
;
2245 pNode
= pNode
->mNext
;
2247 return VFR_RETURN_FATAL_ERROR
;
2251 CVfrDataStorage::GetNameVarStoreInfo (
2252 OUT EFI_VARSTORE_INFO
*Info
,
2257 return VFR_RETURN_FATAL_ERROR
;
2260 if (mCurrVarStorageNode
== NULL
) {
2261 return VFR_RETURN_GET_NVVARSTORE_ERROR
;
2264 Info
->mInfo
.mVarName
= mCurrVarStorageNode
->mStorageInfo
.mNameSpace
.mNameTable
[Index
];
2266 return VFR_RETURN_SUCCESS
;
2269 SVfrDefaultStoreNode::SVfrDefaultStoreNode (
2270 IN EFI_IFR_DEFAULTSTORE
*ObjBinAddr
,
2272 IN EFI_STRING_ID DefaultStoreNameId
,
2276 mObjBinAddr
= ObjBinAddr
;
2278 if (RefName
!= NULL
) {
2279 mRefName
= new CHAR8
[strlen (RefName
) + 1];
2280 strcpy (mRefName
, RefName
);
2286 mDefaultId
= DefaultId
;
2287 mDefaultStoreNameId
= DefaultStoreNameId
;
2290 SVfrDefaultStoreNode::~SVfrDefaultStoreNode (
2294 if (mRefName
!= NULL
) {
2299 CVfrDefaultStore::CVfrDefaultStore (
2303 mDefaultStoreList
= NULL
;
2306 CVfrDefaultStore::~CVfrDefaultStore (
2310 SVfrDefaultStoreNode
*pTmp
= NULL
;
2312 while (mDefaultStoreList
!= NULL
) {
2313 pTmp
= mDefaultStoreList
;
2314 mDefaultStoreList
= mDefaultStoreList
->mNext
;
2320 CVfrDefaultStore::RegisterDefaultStore (
2321 IN CHAR8
*ObjBinAddr
,
2323 IN EFI_STRING_ID DefaultStoreNameId
,
2327 SVfrDefaultStoreNode
*pNode
= NULL
;
2329 if (RefName
== NULL
) {
2330 return VFR_RETURN_FATAL_ERROR
;
2333 for (pNode
= mDefaultStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2334 if (strcmp (pNode
->mRefName
, RefName
) == 0) {
2335 return VFR_RETURN_REDEFINED
;
2339 if ((pNode
= new SVfrDefaultStoreNode ((EFI_IFR_DEFAULTSTORE
*)ObjBinAddr
, RefName
, DefaultStoreNameId
, DefaultId
)) == NULL
) {
2340 return VFR_RETURN_OUT_FOR_RESOURCES
;
2343 pNode
->mNext
= mDefaultStoreList
;
2344 mDefaultStoreList
= pNode
;
2346 return VFR_RETURN_SUCCESS
;
2350 * assign new reference name or new default store name id only if
2351 * the original is invalid
2354 CVfrDefaultStore::ReRegisterDefaultStoreById (
2355 IN UINT16 DefaultId
,
2357 IN EFI_STRING_ID DefaultStoreNameId
2360 SVfrDefaultStoreNode
*pNode
= NULL
;
2362 for (pNode
= mDefaultStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2363 if (pNode
->mDefaultId
== DefaultId
) {
2368 if (pNode
== NULL
) {
2369 return VFR_RETURN_UNDEFINED
;
2371 if (pNode
->mDefaultStoreNameId
== EFI_STRING_ID_INVALID
) {
2372 pNode
->mDefaultStoreNameId
= DefaultStoreNameId
;
2373 if (pNode
->mObjBinAddr
!= NULL
) {
2374 pNode
->mObjBinAddr
->DefaultName
= DefaultStoreNameId
;
2377 return VFR_RETURN_REDEFINED
;
2380 if (RefName
!= NULL
) {
2381 delete pNode
->mRefName
;
2382 pNode
->mRefName
= new CHAR8
[strlen (RefName
) + 1];
2383 if (pNode
->mRefName
!= NULL
) {
2384 strcpy (pNode
->mRefName
, RefName
);
2389 return VFR_RETURN_SUCCESS
;
2393 CVfrDefaultStore::DefaultIdRegistered (
2397 SVfrDefaultStoreNode
*pNode
= NULL
;
2399 for (pNode
= mDefaultStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2400 if (pNode
->mDefaultId
== DefaultId
) {
2409 CVfrDefaultStore::GetDefaultId (
2411 OUT UINT16
*DefaultId
2414 SVfrDefaultStoreNode
*pTmp
= NULL
;
2416 if (DefaultId
== NULL
) {
2417 return VFR_RETURN_FATAL_ERROR
;
2420 for (pTmp
= mDefaultStoreList
; pTmp
!= NULL
; pTmp
= pTmp
->mNext
) {
2421 if (strcmp (pTmp
->mRefName
, RefName
) == 0) {
2422 *DefaultId
= pTmp
->mDefaultId
;
2423 return VFR_RETURN_SUCCESS
;
2427 return VFR_RETURN_UNDEFINED
;
2431 CVfrDefaultStore::BufferVarStoreAltConfigAdd (
2432 IN EFI_VARSTORE_ID DefaultId
,
2433 IN EFI_VARSTORE_INFO
&Info
,
2434 IN CHAR8
*VarStoreName
,
2435 IN EFI_GUID
*VarStoreGuid
,
2437 IN EFI_IFR_TYPE_VALUE Value
2440 SVfrDefaultStoreNode
*pNode
= NULL
;
2441 CHAR8 NewAltCfg
[2 * 2 * sizeof (UINT16
) + 1] = {0,};
2442 INTN Returnvalue
= 0;
2444 if (VarStoreName
== NULL
) {
2445 return VFR_RETURN_FATAL_ERROR
;
2448 for (pNode
= mDefaultStoreList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2449 if (pNode
->mDefaultId
== DefaultId
) {
2454 if (pNode
== NULL
) {
2455 return VFR_RETURN_UNDEFINED
;
2458 gCVfrBufferConfig
.Open ();
2460 sprintf (NewAltCfg
, "%04x", pNode
->mDefaultId
);
2461 if ((Returnvalue
= gCVfrBufferConfig
.Select(VarStoreName
, VarStoreGuid
)) == 0) {
2462 if ((Returnvalue
= gCVfrBufferConfig
.Write ('a', VarStoreName
, VarStoreGuid
, NewAltCfg
, Type
, Info
.mInfo
.mVarOffset
, Info
.mVarTotalSize
, Value
)) != 0) {
2467 gCVfrBufferConfig
.Close ();
2469 return VFR_RETURN_SUCCESS
;
2472 gCVfrBufferConfig
.Close ();
2473 return (EFI_VFR_RETURN_CODE
)Returnvalue
;
2476 SVfrRuleNode::SVfrRuleNode (
2481 if (RuleName
!= NULL
) {
2482 mRuleName
= new CHAR8
[strlen (RuleName
) + 1];
2483 strcpy (mRuleName
, RuleName
);
2492 SVfrRuleNode::~SVfrRuleNode (
2496 if (mRuleName
!= NULL
) {
2501 CVfrRulesDB::CVfrRulesDB ()
2504 mFreeRuleId
= EFI_VARSTORE_ID_START
;
2507 CVfrRulesDB::~CVfrRulesDB ()
2509 SVfrRuleNode
*pNode
;
2511 while(mRuleList
!= NULL
) {
2513 mRuleList
= mRuleList
->mNext
;
2519 CVfrRulesDB::RegisterRule (
2525 if (RuleName
== NULL
) {
2529 if ((pNew
= new SVfrRuleNode (RuleName
, mFreeRuleId
)) == NULL
) {
2535 pNew
->mNext
= mRuleList
;
2540 CVfrRulesDB::GetRuleId (
2544 SVfrRuleNode
*pNode
;
2546 if (RuleName
== NULL
) {
2547 return EFI_RULE_ID_INVALID
;
2550 for (pNode
= mRuleList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2551 if (strcmp (pNode
->mRuleName
, RuleName
) == 0) {
2552 return pNode
->mRuleId
;
2556 return EFI_RULE_ID_INVALID
;
2559 CVfrRulesDB gCVfrRulesDB
;
2561 EFI_VARSTORE_INFO::EFI_VARSTORE_INFO (
2565 mVarStoreId
= EFI_VARSTORE_ID_INVALID
;
2566 mInfo
.mVarName
= EFI_STRING_ID_INVALID
;
2567 mInfo
.mVarOffset
= EFI_VAROFFSET_INVALID
;
2568 mVarType
= EFI_IFR_TYPE_OTHER
;
2573 EFI_VARSTORE_INFO::EFI_VARSTORE_INFO (
2574 IN EFI_VARSTORE_INFO
&Info
2577 mVarStoreId
= Info
.mVarStoreId
;
2578 mInfo
.mVarName
= Info
.mInfo
.mVarName
;
2579 mInfo
.mVarOffset
= Info
.mInfo
.mVarOffset
;
2580 mVarType
= Info
.mVarType
;
2581 mVarTotalSize
= Info
.mVarTotalSize
;
2582 mIsBitVar
= Info
.mIsBitVar
;
2586 EFI_VARSTORE_INFO::operator= (
2587 IN CONST EFI_VARSTORE_INFO
&Info
2590 if (this != &Info
) {
2591 mVarStoreId
= Info
.mVarStoreId
;
2592 mInfo
.mVarName
= Info
.mInfo
.mVarName
;
2593 mInfo
.mVarOffset
= Info
.mInfo
.mVarOffset
;
2594 mVarType
= Info
.mVarType
;
2595 mVarTotalSize
= Info
.mVarTotalSize
;
2596 mIsBitVar
= Info
.mIsBitVar
;
2603 EFI_VARSTORE_INFO::operator == (
2604 IN EFI_VARSTORE_INFO
*Info
2607 if ((mVarStoreId
== Info
->mVarStoreId
) &&
2608 (mInfo
.mVarName
== Info
->mInfo
.mVarName
) &&
2609 (mInfo
.mVarOffset
== Info
->mInfo
.mVarOffset
) &&
2610 (mVarType
== Info
->mVarType
) &&
2611 (mVarTotalSize
== Info
->mVarTotalSize
) &&
2612 (mIsBitVar
== Info
->mIsBitVar
)) {
2619 BufferVarStoreFieldInfoNode::BufferVarStoreFieldInfoNode(
2620 IN EFI_VARSTORE_INFO
*Info
2623 mVarStoreInfo
.mVarType
= Info
->mVarType
;
2624 mVarStoreInfo
.mVarTotalSize
= Info
->mVarTotalSize
;
2625 mVarStoreInfo
.mInfo
.mVarOffset
= Info
->mInfo
.mVarOffset
;
2626 mVarStoreInfo
.mVarStoreId
= Info
->mVarStoreId
;
2630 BufferVarStoreFieldInfoNode::~BufferVarStoreFieldInfoNode ()
2632 mVarStoreInfo
.mVarType
= EFI_IFR_TYPE_OTHER
;
2633 mVarStoreInfo
.mVarTotalSize
= 0;
2634 mVarStoreInfo
.mInfo
.mVarOffset
= EFI_VAROFFSET_INVALID
;
2635 mVarStoreInfo
.mVarStoreId
= EFI_VARSTORE_ID_INVALID
;
2639 static EFI_VARSTORE_INFO gEfiInvalidVarStoreInfo
;
2642 CVfrQuestionDB::GetFreeQuestionId (
2646 UINT32 Index
, Mask
, Offset
;
2648 for (Index
= 0; Index
< EFI_FREE_QUESTION_ID_BITMAP_SIZE
; Index
++) {
2649 if (mFreeQIdBitMap
[Index
] != 0xFFFFFFFF) {
2654 if (Index
== EFI_FREE_QUESTION_ID_BITMAP_SIZE
) {
2655 return EFI_QUESTION_ID_INVALID
;
2658 for (Offset
= 0, Mask
= 0x80000000; Mask
!= 0; Mask
>>= 1, Offset
++) {
2659 if ((mFreeQIdBitMap
[Index
] & Mask
) == 0) {
2660 mFreeQIdBitMap
[Index
] |= Mask
;
2661 return (EFI_QUESTION_ID
)((Index
<< EFI_BITS_SHIFT_PER_UINT32
) + Offset
);
2665 return EFI_QUESTION_ID_INVALID
;
2669 CVfrQuestionDB::ChekQuestionIdFree (
2670 IN EFI_QUESTION_ID QId
2673 UINT32 Index
= (QId
/ EFI_BITS_PER_UINT32
);
2674 UINT32 Offset
= (QId
% EFI_BITS_PER_UINT32
);
2676 return (mFreeQIdBitMap
[Index
] & (0x80000000 >> Offset
)) == 0;
2680 CVfrQuestionDB::MarkQuestionIdUsed (
2681 IN EFI_QUESTION_ID QId
2684 UINT32 Index
= (QId
/ EFI_BITS_PER_UINT32
);
2685 UINT32 Offset
= (QId
% EFI_BITS_PER_UINT32
);
2687 mFreeQIdBitMap
[Index
] |= (0x80000000 >> Offset
);
2691 CVfrQuestionDB::MarkQuestionIdUnused (
2692 IN EFI_QUESTION_ID QId
2695 UINT32 Index
= (QId
/ EFI_BITS_PER_UINT32
);
2696 UINT32 Offset
= (QId
% EFI_BITS_PER_UINT32
);
2698 mFreeQIdBitMap
[Index
] &= ~(0x80000000 >> Offset
);
2701 SVfrQuestionNode::SVfrQuestionNode (
2709 mQuestionId
= EFI_QUESTION_ID_INVALID
;
2712 mQtype
= QUESTION_NORMAL
;
2715 mName
= new CHAR8
[strlen ("$DEFAULT") + 1];
2716 strcpy (mName
, "$DEFAULT");
2718 mName
= new CHAR8
[strlen (Name
) + 1];
2719 strcpy (mName
, Name
);
2722 if (VarIdStr
!= NULL
) {
2723 mVarIdStr
= new CHAR8
[strlen (VarIdStr
) + 1];
2724 strcpy (mVarIdStr
, VarIdStr
);
2726 mVarIdStr
= new CHAR8
[strlen ("$") + 1];
2727 strcpy (mVarIdStr
, "$");
2731 SVfrQuestionNode::~SVfrQuestionNode (
2735 if (mName
!= NULL
) {
2739 if (mVarIdStr
!= NULL
) {
2744 CVfrQuestionDB::CVfrQuestionDB ()
2748 for (Index
= 0; Index
< EFI_FREE_QUESTION_ID_BITMAP_SIZE
; Index
++) {
2749 mFreeQIdBitMap
[Index
] = 0;
2752 // Question ID 0 is reserved.
2753 mFreeQIdBitMap
[0] = 0x80000000;
2754 mQuestionList
= NULL
;
2757 CVfrQuestionDB::~CVfrQuestionDB ()
2759 SVfrQuestionNode
*pNode
;
2761 while (mQuestionList
!= NULL
) {
2762 pNode
= mQuestionList
;
2763 mQuestionList
= mQuestionList
->mNext
;
2769 // Reset to init state
2772 CVfrQuestionDB::ResetInit(
2777 SVfrQuestionNode
*pNode
;
2779 while (mQuestionList
!= NULL
) {
2780 pNode
= mQuestionList
;
2781 mQuestionList
= mQuestionList
->mNext
;
2785 for (Index
= 0; Index
< EFI_FREE_QUESTION_ID_BITMAP_SIZE
; Index
++) {
2786 mFreeQIdBitMap
[Index
] = 0;
2789 // Question ID 0 is reserved.
2790 mFreeQIdBitMap
[0] = 0x80000000;
2791 mQuestionList
= NULL
;
2795 CVfrQuestionDB::PrintAllQuestion (
2799 SVfrQuestionNode
*pNode
= NULL
;
2801 for (pNode
= mQuestionList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
2802 printf ("Question VarId is %s and QuestionId is 0x%x\n", pNode
->mVarIdStr
, pNode
->mQuestionId
);
2807 CVfrQuestionDB::RegisterQuestion (
2810 IN OUT EFI_QUESTION_ID
&QuestionId
2813 SVfrQuestionNode
*pNode
= NULL
;
2815 if ((Name
!= NULL
) && (FindQuestion(Name
) == VFR_RETURN_SUCCESS
)) {
2816 return VFR_RETURN_REDEFINED
;
2819 if ((pNode
= new SVfrQuestionNode (Name
, VarIdStr
)) == NULL
) {
2820 return VFR_RETURN_OUT_FOR_RESOURCES
;
2823 if (QuestionId
== EFI_QUESTION_ID_INVALID
) {
2824 QuestionId
= GetFreeQuestionId ();
2826 if (ChekQuestionIdFree (QuestionId
) == FALSE
) {
2828 return VFR_RETURN_QUESTIONID_REDEFINED
;
2830 MarkQuestionIdUsed (QuestionId
);
2832 pNode
->mQuestionId
= QuestionId
;
2834 pNode
->mNext
= mQuestionList
;
2835 mQuestionList
= pNode
;
2837 gCFormPkg
.DoPendingAssign (VarIdStr
, (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
2839 return VFR_RETURN_SUCCESS
;
2843 CVfrQuestionDB::RegisterOldDateQuestion (
2844 IN CHAR8
*YearVarId
,
2845 IN CHAR8
*MonthVarId
,
2847 IN OUT EFI_QUESTION_ID
&QuestionId
2850 SVfrQuestionNode
*pNode
[3] = {NULL
, };
2853 if ((YearVarId
== NULL
) || (MonthVarId
== NULL
) || (DayVarId
== NULL
)) {
2857 if ((pNode
[0] = new SVfrQuestionNode (NULL
, YearVarId
, DATE_YEAR_BITMASK
)) == NULL
) {
2860 if ((pNode
[1] = new SVfrQuestionNode (NULL
, MonthVarId
, DATE_MONTH_BITMASK
)) == NULL
) {
2863 if ((pNode
[2] = new SVfrQuestionNode (NULL
, DayVarId
, DATE_DAY_BITMASK
)) == NULL
) {
2867 if (QuestionId
== EFI_QUESTION_ID_INVALID
) {
2868 QuestionId
= GetFreeQuestionId ();
2870 if (ChekQuestionIdFree (QuestionId
) == FALSE
) {
2873 MarkQuestionIdUsed (QuestionId
);
2876 pNode
[0]->mQuestionId
= QuestionId
;
2877 pNode
[1]->mQuestionId
= QuestionId
;
2878 pNode
[2]->mQuestionId
= QuestionId
;
2879 pNode
[0]->mQtype
= QUESTION_DATE
;
2880 pNode
[1]->mQtype
= QUESTION_DATE
;
2881 pNode
[2]->mQtype
= QUESTION_DATE
;
2882 pNode
[0]->mNext
= pNode
[1];
2883 pNode
[1]->mNext
= pNode
[2];
2884 pNode
[2]->mNext
= mQuestionList
;
2885 mQuestionList
= pNode
[0];
2887 gCFormPkg
.DoPendingAssign (YearVarId
, (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
2888 gCFormPkg
.DoPendingAssign (MonthVarId
, (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
2889 gCFormPkg
.DoPendingAssign (DayVarId
, (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
2894 for (Index
= 0; Index
< 3; Index
++) {
2895 if (pNode
[Index
] != NULL
) {
2896 delete pNode
[Index
];
2899 QuestionId
= EFI_QUESTION_ID_INVALID
;
2903 CVfrQuestionDB::RegisterNewDateQuestion (
2905 IN CHAR8
*BaseVarId
,
2906 IN OUT EFI_QUESTION_ID
&QuestionId
2909 SVfrQuestionNode
*pNode
[3] = {NULL
, };
2911 CHAR8
*VarIdStr
[3] = {NULL
, };
2914 if (BaseVarId
== NULL
&& Name
== NULL
) {
2915 if (QuestionId
== EFI_QUESTION_ID_INVALID
) {
2916 QuestionId
= GetFreeQuestionId ();
2918 if (ChekQuestionIdFree (QuestionId
) == FALSE
) {
2921 MarkQuestionIdUsed (QuestionId
);
2926 if (BaseVarId
!= NULL
) {
2927 Len
= strlen (BaseVarId
);
2929 VarIdStr
[0] = new CHAR8
[Len
+ strlen (".Year") + 1];
2930 if (VarIdStr
[0] != NULL
) {
2931 strcpy (VarIdStr
[0], BaseVarId
);
2932 strcat (VarIdStr
[0], ".Year");
2934 VarIdStr
[1] = new CHAR8
[Len
+ strlen (".Month") + 1];
2935 if (VarIdStr
[1] != NULL
) {
2936 strcpy (VarIdStr
[1], BaseVarId
);
2937 strcat (VarIdStr
[1], ".Month");
2939 VarIdStr
[2] = new CHAR8
[Len
+ strlen (".Day") + 1];
2940 if (VarIdStr
[2] != NULL
) {
2941 strcpy (VarIdStr
[2], BaseVarId
);
2942 strcat (VarIdStr
[2], ".Day");
2945 Len
= strlen (Name
);
2947 VarIdStr
[0] = new CHAR8
[Len
+ strlen (".Year") + 1];
2948 if (VarIdStr
[0] != NULL
) {
2949 strcpy (VarIdStr
[0], Name
);
2950 strcat (VarIdStr
[0], ".Year");
2952 VarIdStr
[1] = new CHAR8
[Len
+ strlen (".Month") + 1];
2953 if (VarIdStr
[1] != NULL
) {
2954 strcpy (VarIdStr
[1], Name
);
2955 strcat (VarIdStr
[1], ".Month");
2957 VarIdStr
[2] = new CHAR8
[Len
+ strlen (".Day") + 1];
2958 if (VarIdStr
[2] != NULL
) {
2959 strcpy (VarIdStr
[2], Name
);
2960 strcat (VarIdStr
[2], ".Day");
2964 if ((pNode
[0] = new SVfrQuestionNode (Name
, VarIdStr
[0], DATE_YEAR_BITMASK
)) == NULL
) {
2967 if ((pNode
[1] = new SVfrQuestionNode (Name
, VarIdStr
[1], DATE_MONTH_BITMASK
)) == NULL
) {
2970 if ((pNode
[2] = new SVfrQuestionNode (Name
, VarIdStr
[2], DATE_DAY_BITMASK
)) == NULL
) {
2974 if (QuestionId
== EFI_QUESTION_ID_INVALID
) {
2975 QuestionId
= GetFreeQuestionId ();
2977 if (ChekQuestionIdFree (QuestionId
) == FALSE
) {
2980 MarkQuestionIdUsed (QuestionId
);
2983 pNode
[0]->mQuestionId
= QuestionId
;
2984 pNode
[1]->mQuestionId
= QuestionId
;
2985 pNode
[2]->mQuestionId
= QuestionId
;
2986 pNode
[0]->mQtype
= QUESTION_DATE
;
2987 pNode
[1]->mQtype
= QUESTION_DATE
;
2988 pNode
[2]->mQtype
= QUESTION_DATE
;
2989 pNode
[0]->mNext
= pNode
[1];
2990 pNode
[1]->mNext
= pNode
[2];
2991 pNode
[2]->mNext
= mQuestionList
;
2992 mQuestionList
= pNode
[0];
2994 for (Index
= 0; Index
< 3; Index
++) {
2995 if (VarIdStr
[Index
] != NULL
) {
2996 delete[] VarIdStr
[Index
];
2997 VarIdStr
[Index
] = NULL
;
3001 gCFormPkg
.DoPendingAssign (VarIdStr
[0], (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3002 gCFormPkg
.DoPendingAssign (VarIdStr
[1], (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3003 gCFormPkg
.DoPendingAssign (VarIdStr
[2], (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3008 for (Index
= 0; Index
< 3; Index
++) {
3009 if (pNode
[Index
] != NULL
) {
3010 delete pNode
[Index
];
3013 if (VarIdStr
[Index
] != NULL
) {
3014 delete[] VarIdStr
[Index
];
3015 VarIdStr
[Index
] = NULL
;
3021 CVfrQuestionDB::RegisterOldTimeQuestion (
3022 IN CHAR8
*HourVarId
,
3023 IN CHAR8
*MinuteVarId
,
3024 IN CHAR8
*SecondVarId
,
3025 IN OUT EFI_QUESTION_ID
&QuestionId
3028 SVfrQuestionNode
*pNode
[3] = {NULL
, };
3031 if ((HourVarId
== NULL
) || (MinuteVarId
== NULL
) || (SecondVarId
== NULL
)) {
3035 if ((pNode
[0] = new SVfrQuestionNode (NULL
, HourVarId
, TIME_HOUR_BITMASK
)) == NULL
) {
3038 if ((pNode
[1] = new SVfrQuestionNode (NULL
, MinuteVarId
, TIME_MINUTE_BITMASK
)) == NULL
) {
3041 if ((pNode
[2] = new SVfrQuestionNode (NULL
, SecondVarId
, TIME_SECOND_BITMASK
)) == NULL
) {
3045 if (QuestionId
== EFI_QUESTION_ID_INVALID
) {
3046 QuestionId
= GetFreeQuestionId ();
3048 if (ChekQuestionIdFree (QuestionId
) == FALSE
) {
3051 MarkQuestionIdUsed (QuestionId
);
3054 pNode
[0]->mQuestionId
= QuestionId
;
3055 pNode
[1]->mQuestionId
= QuestionId
;
3056 pNode
[2]->mQuestionId
= QuestionId
;
3057 pNode
[0]->mQtype
= QUESTION_TIME
;
3058 pNode
[1]->mQtype
= QUESTION_TIME
;
3059 pNode
[2]->mQtype
= QUESTION_TIME
;
3060 pNode
[0]->mNext
= pNode
[1];
3061 pNode
[1]->mNext
= pNode
[2];
3062 pNode
[2]->mNext
= mQuestionList
;
3063 mQuestionList
= pNode
[0];
3065 gCFormPkg
.DoPendingAssign (HourVarId
, (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3066 gCFormPkg
.DoPendingAssign (MinuteVarId
, (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3067 gCFormPkg
.DoPendingAssign (SecondVarId
, (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3072 for (Index
= 0; Index
< 3; Index
++) {
3073 if (pNode
[Index
] != NULL
) {
3074 delete pNode
[Index
];
3077 QuestionId
= EFI_QUESTION_ID_INVALID
;
3081 CVfrQuestionDB::RegisterNewTimeQuestion (
3083 IN CHAR8
*BaseVarId
,
3084 IN OUT EFI_QUESTION_ID
&QuestionId
3087 SVfrQuestionNode
*pNode
[3] = {NULL
, };
3089 CHAR8
*VarIdStr
[3] = {NULL
, };
3092 if (BaseVarId
== NULL
&& Name
== NULL
) {
3093 if (QuestionId
== EFI_QUESTION_ID_INVALID
) {
3094 QuestionId
= GetFreeQuestionId ();
3096 if (ChekQuestionIdFree (QuestionId
) == FALSE
) {
3099 MarkQuestionIdUsed (QuestionId
);
3104 if (BaseVarId
!= NULL
) {
3105 Len
= strlen (BaseVarId
);
3107 VarIdStr
[0] = new CHAR8
[Len
+ strlen (".Hour") + 1];
3108 if (VarIdStr
[0] != NULL
) {
3109 strcpy (VarIdStr
[0], BaseVarId
);
3110 strcat (VarIdStr
[0], ".Hour");
3112 VarIdStr
[1] = new CHAR8
[Len
+ strlen (".Minute") + 1];
3113 if (VarIdStr
[1] != NULL
) {
3114 strcpy (VarIdStr
[1], BaseVarId
);
3115 strcat (VarIdStr
[1], ".Minute");
3117 VarIdStr
[2] = new CHAR8
[Len
+ strlen (".Second") + 1];
3118 if (VarIdStr
[2] != NULL
) {
3119 strcpy (VarIdStr
[2], BaseVarId
);
3120 strcat (VarIdStr
[2], ".Second");
3123 Len
= strlen (Name
);
3125 VarIdStr
[0] = new CHAR8
[Len
+ strlen (".Hour") + 1];
3126 if (VarIdStr
[0] != NULL
) {
3127 strcpy (VarIdStr
[0], Name
);
3128 strcat (VarIdStr
[0], ".Hour");
3130 VarIdStr
[1] = new CHAR8
[Len
+ strlen (".Minute") + 1];
3131 if (VarIdStr
[1] != NULL
) {
3132 strcpy (VarIdStr
[1], Name
);
3133 strcat (VarIdStr
[1], ".Minute");
3135 VarIdStr
[2] = new CHAR8
[Len
+ strlen (".Second") + 1];
3136 if (VarIdStr
[2] != NULL
) {
3137 strcpy (VarIdStr
[2], Name
);
3138 strcat (VarIdStr
[2], ".Second");
3142 if ((pNode
[0] = new SVfrQuestionNode (Name
, VarIdStr
[0], TIME_HOUR_BITMASK
)) == NULL
) {
3145 if ((pNode
[1] = new SVfrQuestionNode (Name
, VarIdStr
[1], TIME_MINUTE_BITMASK
)) == NULL
) {
3148 if ((pNode
[2] = new SVfrQuestionNode (Name
, VarIdStr
[2], TIME_SECOND_BITMASK
)) == NULL
) {
3152 if (QuestionId
== EFI_QUESTION_ID_INVALID
) {
3153 QuestionId
= GetFreeQuestionId ();
3155 if (ChekQuestionIdFree (QuestionId
) == FALSE
) {
3158 MarkQuestionIdUsed (QuestionId
);
3161 pNode
[0]->mQuestionId
= QuestionId
;
3162 pNode
[1]->mQuestionId
= QuestionId
;
3163 pNode
[2]->mQuestionId
= QuestionId
;
3164 pNode
[0]->mQtype
= QUESTION_TIME
;
3165 pNode
[1]->mQtype
= QUESTION_TIME
;
3166 pNode
[2]->mQtype
= QUESTION_TIME
;
3167 pNode
[0]->mNext
= pNode
[1];
3168 pNode
[1]->mNext
= pNode
[2];
3169 pNode
[2]->mNext
= mQuestionList
;
3170 mQuestionList
= pNode
[0];
3172 for (Index
= 0; Index
< 3; Index
++) {
3173 if (VarIdStr
[Index
] != NULL
) {
3174 delete[] VarIdStr
[Index
];
3175 VarIdStr
[Index
] = NULL
;
3179 gCFormPkg
.DoPendingAssign (VarIdStr
[0], (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3180 gCFormPkg
.DoPendingAssign (VarIdStr
[1], (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3181 gCFormPkg
.DoPendingAssign (VarIdStr
[2], (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3186 for (Index
= 0; Index
< 3; Index
++) {
3187 if (pNode
[Index
] != NULL
) {
3188 delete pNode
[Index
];
3191 if (VarIdStr
[Index
] != NULL
) {
3192 delete[] VarIdStr
[Index
];
3193 VarIdStr
[Index
] = NULL
;
3199 CVfrQuestionDB::RegisterRefQuestion (
3201 IN CHAR8
*BaseVarId
,
3202 IN OUT EFI_QUESTION_ID
&QuestionId
3205 SVfrQuestionNode
*pNode
[4] = {NULL
, };
3207 CHAR8
*VarIdStr
[4] = {NULL
, };
3210 if (BaseVarId
== NULL
&& Name
== NULL
) {
3214 if (BaseVarId
!= NULL
) {
3215 Len
= strlen (BaseVarId
);
3217 VarIdStr
[0] = new CHAR8
[Len
+ strlen (".QuestionId") + 1];
3218 if (VarIdStr
[0] != NULL
) {
3219 strcpy (VarIdStr
[0], BaseVarId
);
3220 strcat (VarIdStr
[0], ".QuestionId");
3222 VarIdStr
[1] = new CHAR8
[Len
+ strlen (".FormId") + 1];
3223 if (VarIdStr
[1] != NULL
) {
3224 strcpy (VarIdStr
[1], BaseVarId
);
3225 strcat (VarIdStr
[1], ".FormId");
3227 VarIdStr
[2] = new CHAR8
[Len
+ strlen (".FormSetGuid") + 1];
3228 if (VarIdStr
[2] != NULL
) {
3229 strcpy (VarIdStr
[2], BaseVarId
);
3230 strcat (VarIdStr
[2], ".FormSetGuid");
3232 VarIdStr
[3] = new CHAR8
[Len
+ strlen (".DevicePath") + 1];
3233 if (VarIdStr
[3] != NULL
) {
3234 strcpy (VarIdStr
[3], BaseVarId
);
3235 strcat (VarIdStr
[3], ".DevicePath");
3238 Len
= strlen (Name
);
3240 VarIdStr
[0] = new CHAR8
[Len
+ strlen (".QuestionId") + 1];
3241 if (VarIdStr
[0] != NULL
) {
3242 strcpy (VarIdStr
[0], Name
);
3243 strcat (VarIdStr
[0], ".QuestionId");
3245 VarIdStr
[1] = new CHAR8
[Len
+ strlen (".FormId") + 1];
3246 if (VarIdStr
[1] != NULL
) {
3247 strcpy (VarIdStr
[1], Name
);
3248 strcat (VarIdStr
[1], ".FormId");
3250 VarIdStr
[2] = new CHAR8
[Len
+ strlen (".FormSetGuid") + 1];
3251 if (VarIdStr
[2] != NULL
) {
3252 strcpy (VarIdStr
[2], Name
);
3253 strcat (VarIdStr
[2], ".FormSetGuid");
3255 VarIdStr
[3] = new CHAR8
[Len
+ strlen (".DevicePath") + 1];
3256 if (VarIdStr
[3] != NULL
) {
3257 strcpy (VarIdStr
[3], Name
);
3258 strcat (VarIdStr
[3], ".DevicePath");
3262 if ((pNode
[0] = new SVfrQuestionNode (Name
, VarIdStr
[0])) == NULL
) {
3265 if ((pNode
[1] = new SVfrQuestionNode (Name
, VarIdStr
[1])) == NULL
) {
3268 if ((pNode
[2] = new SVfrQuestionNode (Name
, VarIdStr
[2])) == NULL
) {
3271 if ((pNode
[3] = new SVfrQuestionNode (Name
, VarIdStr
[3])) == NULL
) {
3275 if (QuestionId
== EFI_QUESTION_ID_INVALID
) {
3276 QuestionId
= GetFreeQuestionId ();
3278 if (ChekQuestionIdFree (QuestionId
) == FALSE
) {
3281 MarkQuestionIdUsed (QuestionId
);
3284 pNode
[0]->mQuestionId
= QuestionId
;
3285 pNode
[1]->mQuestionId
= QuestionId
;
3286 pNode
[2]->mQuestionId
= QuestionId
;
3287 pNode
[3]->mQuestionId
= QuestionId
;
3288 pNode
[0]->mQtype
= QUESTION_REF
;
3289 pNode
[1]->mQtype
= QUESTION_REF
;
3290 pNode
[2]->mQtype
= QUESTION_REF
;
3291 pNode
[3]->mQtype
= QUESTION_REF
;
3292 pNode
[0]->mNext
= pNode
[1];
3293 pNode
[1]->mNext
= pNode
[2];
3294 pNode
[2]->mNext
= pNode
[3];
3295 pNode
[3]->mNext
= mQuestionList
;
3296 mQuestionList
= pNode
[0];
3298 gCFormPkg
.DoPendingAssign (VarIdStr
[0], (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3299 gCFormPkg
.DoPendingAssign (VarIdStr
[1], (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3300 gCFormPkg
.DoPendingAssign (VarIdStr
[2], (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3301 gCFormPkg
.DoPendingAssign (VarIdStr
[3], (VOID
*)&QuestionId
, sizeof(EFI_QUESTION_ID
));
3306 for (Index
= 0; Index
< 4; Index
++) {
3307 if (pNode
[Index
] != NULL
) {
3308 delete pNode
[Index
];
3311 if (VarIdStr
[Index
] != NULL
) {
3312 delete VarIdStr
[Index
];
3318 CVfrQuestionDB::UpdateQuestionId (
3319 IN EFI_QUESTION_ID QId
,
3320 IN EFI_QUESTION_ID NewQId
3323 SVfrQuestionNode
*pNode
= NULL
;
3325 if (QId
== NewQId
) {
3327 return VFR_RETURN_SUCCESS
;
3330 if (ChekQuestionIdFree (NewQId
) == FALSE
) {
3331 return VFR_RETURN_REDEFINED
;
3334 for (pNode
= mQuestionList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
3335 if (pNode
->mQuestionId
== QId
) {
3340 if (pNode
== NULL
) {
3341 return VFR_RETURN_UNDEFINED
;
3344 MarkQuestionIdUnused (QId
);
3345 pNode
->mQuestionId
= NewQId
;
3346 MarkQuestionIdUsed (NewQId
);
3348 gCFormPkg
.DoPendingAssign (pNode
->mVarIdStr
, (VOID
*)&NewQId
, sizeof(EFI_QUESTION_ID
));
3350 return VFR_RETURN_SUCCESS
;
3354 CVfrQuestionDB::GetQuestionId (
3357 OUT EFI_QUESTION_ID
&QuestionId
,
3358 OUT UINT32
&BitMask
,
3359 OUT EFI_QUESION_TYPE
*QType
3362 SVfrQuestionNode
*pNode
;
3364 QuestionId
= EFI_QUESTION_ID_INVALID
;
3365 BitMask
= 0x00000000;
3366 if (QType
!= NULL
) {
3367 *QType
= QUESTION_NORMAL
;
3370 if ((Name
== NULL
) && (VarIdStr
== NULL
)) {
3374 for (pNode
= mQuestionList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
3376 if (strcmp (pNode
->mName
, Name
) != 0) {
3381 if (VarIdStr
!= NULL
) {
3382 if (strcmp (pNode
->mVarIdStr
, VarIdStr
) != 0) {
3387 QuestionId
= pNode
->mQuestionId
;
3388 BitMask
= pNode
->mBitMask
;
3389 if (QType
!= NULL
) {
3390 *QType
= pNode
->mQtype
;
3399 CVfrQuestionDB::FindQuestion (
3400 IN EFI_QUESTION_ID QuestionId
3403 SVfrQuestionNode
*pNode
;
3405 if (QuestionId
== EFI_QUESTION_ID_INVALID
) {
3406 return VFR_RETURN_INVALID_PARAMETER
;
3409 for (pNode
= mQuestionList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
3410 if (pNode
->mQuestionId
== QuestionId
) {
3411 return VFR_RETURN_SUCCESS
;
3415 return VFR_RETURN_UNDEFINED
;
3419 CVfrQuestionDB::FindQuestion (
3423 SVfrQuestionNode
*pNode
;
3426 return VFR_RETURN_FATAL_ERROR
;
3429 for (pNode
= mQuestionList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
3430 if (strcmp (pNode
->mName
, Name
) == 0) {
3431 return VFR_RETURN_SUCCESS
;
3435 return VFR_RETURN_UNDEFINED
;
3438 CVfrStringDB::CVfrStringDB ()
3440 mStringFileName
= NULL
;
3443 CVfrStringDB::~CVfrStringDB ()
3445 if (mStringFileName
!= NULL
) {
3446 delete[] mStringFileName
;
3448 mStringFileName
= NULL
;
3453 CVfrStringDB::SetStringFileName(IN CHAR8
*StringFileName
)
3457 if (StringFileName
== NULL
) {
3461 if (mStringFileName
!= NULL
) {
3462 delete[] mStringFileName
;
3465 FileLen
= strlen (StringFileName
) + 1;
3466 mStringFileName
= new CHAR8
[FileLen
];
3467 if (mStringFileName
== NULL
) {
3471 strcpy (mStringFileName
, StringFileName
);
3472 mStringFileName
[FileLen
- 1] = '\0';
3477 Returns TRUE or FALSE whether SupportedLanguages contains the best matching language
3478 from a set of supported languages.
3480 @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string that
3481 contains a set of language codes.
3482 @param[in] Language A variable that contains pointers to Null-terminated
3483 ASCII strings that contain one language codes.
3485 @retval FALSE The best matching language could not be found in SupportedLanguages.
3486 @retval TRUE The best matching language could be found in SupportedLanguages.
3490 CVfrStringDB::GetBestLanguage (
3491 IN CONST CHAR8
*SupportedLanguages
,
3495 UINTN CompareLength
;
3496 UINTN LanguageLength
;
3497 CONST CHAR8
*Supported
;
3499 if (SupportedLanguages
== NULL
|| Language
== NULL
){
3504 // Determine the length of the first RFC 4646 language code in Language
3506 for (LanguageLength
= 0; Language
[LanguageLength
] != 0 && Language
[LanguageLength
] != ';'; LanguageLength
++);
3509 // Trim back the length of Language used until it is empty
3511 while (LanguageLength
> 0) {
3513 // Loop through all language codes in SupportedLanguages
3515 for (Supported
= SupportedLanguages
; *Supported
!= '\0'; Supported
+= CompareLength
) {
3517 // Skip ';' characters in Supported
3519 for (; *Supported
!= '\0' && *Supported
== ';'; Supported
++);
3521 // Determine the length of the next language code in Supported
3523 for (CompareLength
= 0; Supported
[CompareLength
] != 0 && Supported
[CompareLength
] != ';'; CompareLength
++);
3525 // If Language is longer than the Supported, then skip to the next language
3527 if (LanguageLength
> CompareLength
) {
3532 // See if the first LanguageLength characters in Supported match Language
3534 if (strncmp (Supported
, Language
, LanguageLength
) == 0) {
3540 // Trim Language from the right to the next '-' character
3542 for (LanguageLength
--; LanguageLength
> 0 && Language
[LanguageLength
] != '-'; LanguageLength
--);
3546 // No matches were found
3553 CVfrStringDB::GetVarStoreNameFormStringId (
3554 IN EFI_STRING_ID StringId
3557 FILE *pInFile
= NULL
;
3562 CHAR16
*UnicodeString
;
3563 CHAR8
*VarStoreName
= NULL
;
3567 CHAR8 LineBuf
[EFI_IFR_MAX_LENGTH
];
3569 EFI_HII_STRING_PACKAGE_HDR
*PkgHeader
;
3571 if (mStringFileName
== NULL
) {
3575 if ((pInFile
= fopen (LongFilePath (mStringFileName
), "rb")) == NULL
) {
3582 fseek (pInFile
, 0, SEEK_END
);
3583 Length
= ftell (pInFile
);
3584 fseek (pInFile
, 0, SEEK_SET
);
3589 StringPtr
= new UINT8
[Length
];
3590 if (StringPtr
== NULL
) {
3594 fread ((char *)StringPtr
, sizeof (UINT8
), Length
, pInFile
);
3597 PkgHeader
= (EFI_HII_STRING_PACKAGE_HDR
*) StringPtr
;
3599 // Check the String package.
3601 if (PkgHeader
->Header
.Type
!= EFI_HII_PACKAGE_STRINGS
) {
3607 // Search the language, get best language base on RFC 4647 matching algorithm.
3609 Current
= StringPtr
;
3610 while (!GetBestLanguage ("en", PkgHeader
->Language
)) {
3611 Current
+= PkgHeader
->Header
.Length
;
3612 PkgHeader
= (EFI_HII_STRING_PACKAGE_HDR
*) Current
;
3614 // If can't find string package base on language, just return the first string package.
3616 if (Current
- StringPtr
>= Length
) {
3617 Current
= StringPtr
;
3618 PkgHeader
= (EFI_HII_STRING_PACKAGE_HDR
*) StringPtr
;
3623 Current
+= PkgHeader
->HdrSize
;
3625 // Find the string block according the stringId.
3627 Status
= FindStringBlock(Current
, StringId
, &NameOffset
, &BlockType
);
3628 if (Status
!= EFI_SUCCESS
) {
3634 // Get varstore name according the string type.
3636 switch (BlockType
) {
3637 case EFI_HII_SIBT_STRING_SCSU
:
3638 case EFI_HII_SIBT_STRING_SCSU_FONT
:
3639 case EFI_HII_SIBT_STRINGS_SCSU
:
3640 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
3641 StringName
= (CHAR8
*)(Current
+ NameOffset
);
3642 VarStoreName
= new CHAR8
[strlen(StringName
) + 1];
3643 strcpy (VarStoreName
, StringName
);
3645 case EFI_HII_SIBT_STRING_UCS2
:
3646 case EFI_HII_SIBT_STRING_UCS2_FONT
:
3647 case EFI_HII_SIBT_STRINGS_UCS2
:
3648 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
3649 UnicodeString
= (CHAR16
*)(Current
+ NameOffset
);
3650 Length
= GetUnicodeStringTextSize ((UINT8
*)UnicodeString
) ;
3651 DestTmp
= new CHAR8
[Length
/ 2 + 1];
3652 VarStoreName
= DestTmp
;
3653 while (*UnicodeString
!= '\0') {
3654 *(DestTmp
++) = (CHAR8
) *(UnicodeString
++);
3664 return VarStoreName
;
3668 CVfrStringDB::FindStringBlock (
3669 IN UINT8
*StringData
,
3670 IN EFI_STRING_ID StringId
,
3671 OUT UINT32
*StringTextOffset
,
3672 OUT UINT8
*BlockType
3676 EFI_STRING_ID CurrentStringId
;
3679 UINT8
*StringTextPtr
;
3684 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
3688 CurrentStringId
= 1;
3691 // Parse the string blocks to get the string text and font.
3693 BlockHdr
= StringData
;
3696 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
3697 switch (*BlockHdr
) {
3698 case EFI_HII_SIBT_STRING_SCSU
:
3699 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
3700 StringTextPtr
= BlockHdr
+ Offset
;
3701 BlockSize
+= Offset
+ strlen ((CHAR8
*) StringTextPtr
) + 1;
3705 case EFI_HII_SIBT_STRING_SCSU_FONT
:
3706 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
3707 StringTextPtr
= BlockHdr
+ Offset
;
3708 BlockSize
+= Offset
+ strlen ((CHAR8
*) StringTextPtr
) + 1;
3712 case EFI_HII_SIBT_STRINGS_SCSU
:
3713 memcpy (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
3714 StringTextPtr
= BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
);
3715 BlockSize
+= StringTextPtr
- BlockHdr
;
3717 for (Index
= 0; Index
< StringCount
; Index
++) {
3718 BlockSize
+= strlen ((CHAR8
*) StringTextPtr
) + 1;
3719 if (CurrentStringId
== StringId
) {
3720 *BlockType
= *BlockHdr
;
3721 *StringTextOffset
= StringTextPtr
- StringData
;
3724 StringTextPtr
= StringTextPtr
+ strlen ((CHAR8
*) StringTextPtr
) + 1;
3729 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
3732 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
3735 StringTextPtr
= BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
3736 BlockSize
+= StringTextPtr
- BlockHdr
;
3738 for (Index
= 0; Index
< StringCount
; Index
++) {
3739 BlockSize
+= strlen ((CHAR8
*) StringTextPtr
) + 1;
3740 if (CurrentStringId
== StringId
) {
3741 *BlockType
= *BlockHdr
;
3742 *StringTextOffset
= StringTextPtr
- StringData
;
3745 StringTextPtr
= StringTextPtr
+ strlen ((CHAR8
*) StringTextPtr
) + 1;
3750 case EFI_HII_SIBT_STRING_UCS2
:
3751 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
3752 StringTextPtr
= BlockHdr
+ Offset
;
3754 // Use StringSize to store the size of the specified string, including the NULL
3757 StringSize
= GetUnicodeStringTextSize (StringTextPtr
);
3758 BlockSize
+= Offset
+ StringSize
;
3762 case EFI_HII_SIBT_STRING_UCS2_FONT
:
3763 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
3764 StringTextPtr
= BlockHdr
+ Offset
;
3766 // Use StrSize to store the size of the specified string, including the NULL
3769 StringSize
= GetUnicodeStringTextSize (StringTextPtr
);
3770 BlockSize
+= Offset
+ StringSize
;
3774 case EFI_HII_SIBT_STRINGS_UCS2
:
3775 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
3776 StringTextPtr
= BlockHdr
+ Offset
;
3777 BlockSize
+= Offset
;
3778 memcpy (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
3779 for (Index
= 0; Index
< StringCount
; Index
++) {
3780 StringSize
= GetUnicodeStringTextSize (StringTextPtr
);
3781 BlockSize
+= StringSize
;
3782 if (CurrentStringId
== StringId
) {
3783 *BlockType
= *BlockHdr
;
3784 *StringTextOffset
= StringTextPtr
- StringData
;
3787 StringTextPtr
= StringTextPtr
+ StringSize
;
3792 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
3793 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
3794 StringTextPtr
= BlockHdr
+ Offset
;
3795 BlockSize
+= Offset
;
3798 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
3801 for (Index
= 0; Index
< StringCount
; Index
++) {
3802 StringSize
= GetUnicodeStringTextSize (StringTextPtr
);
3803 BlockSize
+= StringSize
;
3804 if (CurrentStringId
== StringId
) {
3805 *BlockType
= *BlockHdr
;
3806 *StringTextOffset
= StringTextPtr
- StringData
;
3809 StringTextPtr
= StringTextPtr
+ StringSize
;
3814 case EFI_HII_SIBT_DUPLICATE
:
3815 if (CurrentStringId
== StringId
) {
3817 // Incoming StringId is an id of a duplicate string block.
3818 // Update the StringId to be the previous string block.
3819 // Go back to the header of string block to search.
3823 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
),
3824 sizeof (EFI_STRING_ID
)
3826 CurrentStringId
= 1;
3829 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
3834 case EFI_HII_SIBT_SKIP1
:
3835 SkipCount
= (UINT16
) (*(BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
3836 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
3837 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
3840 case EFI_HII_SIBT_SKIP2
:
3841 memcpy (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
3842 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
3843 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
3846 case EFI_HII_SIBT_EXT1
:
3849 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
3852 BlockSize
+= Length8
;
3855 case EFI_HII_SIBT_EXT2
:
3856 memcpy (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
3857 BlockSize
+= Ext2
.Length
;
3860 case EFI_HII_SIBT_EXT4
:
3863 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
3867 BlockSize
+= Length32
;
3874 if (StringId
> 0 && StringId
!= (EFI_STRING_ID
)(-1)) {
3875 *StringTextOffset
= BlockHdr
- StringData
+ Offset
;
3876 *BlockType
= *BlockHdr
;
3878 if (StringId
== CurrentStringId
- 1) {
3880 // if only one skip item, return EFI_NOT_FOUND.
3882 if(*BlockType
== EFI_HII_SIBT_SKIP2
|| *BlockType
== EFI_HII_SIBT_SKIP1
) {
3883 return EFI_NOT_FOUND
;
3889 if (StringId
< CurrentStringId
- 1) {
3890 return EFI_NOT_FOUND
;
3893 BlockHdr
= StringData
+ BlockSize
;
3896 return EFI_NOT_FOUND
;
3900 CVfrStringDB::GetUnicodeStringTextSize (
3907 StringSize
= sizeof (CHAR16
);
3908 StringPtr
= (UINT16
*)StringSrc
;
3909 while (*StringPtr
++ != L
'\0') {
3910 StringSize
+= sizeof (CHAR16
);
3916 CVfrVarDataTypeDB gCVfrVarDataTypeDB
;
3917 CVfrDefaultStore gCVfrDefaultStore
;
3918 CVfrDataStorage gCVfrDataStorage
;