From: Eric Dong Date: Wed, 6 May 2015 10:40:53 +0000 (+0000) Subject: MdeModulePkg: Add match2 opcode support in SetupBrowserDxe and sample code in DriverS... X-Git-Tag: edk2-stable201903~9912 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=9bd22b08d1a9b0b4c2fd325a928b58acd176d9d1 MdeModulePkg: Add match2 opcode support in SetupBrowserDxe and sample code in DriverSampleDxe Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong Reviewed-by: Liming Gao Reviewed-by: Samer El-Haj-Mahmoud git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17340 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h b/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h index 3c317cdb7b..c8262a45a0 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h +++ b/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h @@ -68,6 +68,7 @@ typedef struct { UINT8 GetDefaultValueFromAccess; EFI_HII_TIME Time; UINT8 RefreshGuidCount; + UINT8 Match2; } DRIVER_SAMPLE_CONFIGURATION; // diff --git a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr index b808abc627..bd90fcd9c3 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr +++ b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr @@ -46,6 +46,9 @@ #define EFI_USER_INFO_ACCESS_SETUP_ADMIN_GUID \ { 0x85b75607, 0xf7ce, 0x471e, { 0xb7, 0xe4, 0x2a, 0xea, 0x5f, 0x72, 0x32, 0xee } } +#define PERL_GUID \ + { 0x63E60A51, 0x497D, 0xD427, {0xC4, 0xA5, 0xB8, 0xAB, 0xDC, 0x3A, 0xAE, 0xB6 }} + // // Labels definition // @@ -650,6 +653,16 @@ formset refresh interval = 3 // Refresh interval in seconds endnumeric; + grayoutif match2 (stringref(STRING_TOKEN(STR_STRING)), stringref(STRING_TOKEN(STR_PATTERN)), PERL_GUID); + numeric + varid = MyIfrNVData.Match2, + prompt = STRING_TOKEN(STR_MATCH2_PROMPT), + help = STRING_TOKEN(STR_MATCH2_HELP), + minimum = 0, + maximum = 243, + endnumeric; + endif; + label LABEL_UPDATE2; label LABEL_END; diff --git a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni index 05dba38b9e..7053b7cc36 100644 Binary files a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni and b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni differ diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Expression.c b/MdeModulePkg/Universal/SetupBrowserDxe/Expression.c index e8829c1855..6c179c445f 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Expression.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Expression.c @@ -1,7 +1,7 @@ /** @file Utility functions for expression evaluation. -Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1475,6 +1475,177 @@ Done: return Status; } +/** + Evaluate opcode EFI_IFR_MATCH2. + + @param FormSet Formset which contains this opcode. + @param SyntaxType Syntax type for match2. + @param Result Evaluation result for this opcode. + + @retval EFI_SUCCESS Opcode evaluation success. + @retval Other Opcode evaluation failed. + +**/ +EFI_STATUS +IfrMatch2 ( + IN FORM_BROWSER_FORMSET *FormSet, + IN EFI_GUID *SyntaxType, + OUT EFI_HII_VALUE *Result + ) +{ + EFI_STATUS Status; + EFI_HII_VALUE Value[2]; + CHAR16 *String[2]; + UINTN Index; + UINTN GuidIndex; + EFI_HANDLE *HandleBuffer; + UINTN BufferSize; + EFI_REGULAR_EXPRESSION_PROTOCOL *RegularExpressionProtocol; + UINTN RegExSyntaxTypeListSize; + EFI_REGEX_SYNTAX_TYPE *RegExSyntaxTypeList; + UINTN CapturesCount; + + // + // String[0] - The string to search + // String[1] - pattern + // + String[0] = NULL; + String[1] = NULL; + HandleBuffer = NULL; + RegExSyntaxTypeList = NULL; + Status = EFI_SUCCESS; + ZeroMem (Value, sizeof (Value)); + + Status = PopExpression (&Value[0]); + if (EFI_ERROR (Status)) { + goto Done; + } + + Status = PopExpression (&Value[1]); + if (EFI_ERROR (Status)) { + goto Done; + } + + for (Index = 0; Index < 2; Index++) { + if (Value[Index].Type != EFI_IFR_TYPE_STRING) { + Result->Type = EFI_IFR_TYPE_UNDEFINED; + Status = EFI_SUCCESS; + goto Done; + } + + String[Index] = GetToken (Value[Index].Value.string, FormSet->HiiHandle); + if (String [Index] == NULL) { + Status = EFI_NOT_FOUND; + goto Done; + } + } + + BufferSize = 0; + HandleBuffer = NULL; + Status = gBS->LocateHandle( + ByProtocol, + &gEfiRegularExpressionProtocolGuid, + NULL, + &BufferSize, + HandleBuffer); + if (Status == EFI_BUFFER_TOO_SMALL) { + HandleBuffer = AllocateZeroPool(BufferSize); + if (HandleBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + Status = gBS->LocateHandle( + ByProtocol, + &gEfiRegularExpressionProtocolGuid, + NULL, + &BufferSize, + HandleBuffer); + + } else if (EFI_ERROR (Status)) { + Value->Type = EFI_IFR_TYPE_UNDEFINED; + Status = EFI_SUCCESS; + goto Done; + } + + for ( Index = 0; Index < BufferSize / sizeof(EFI_HANDLE); Index ++) { + Status = gBS->HandleProtocol ( + HandleBuffer[Index], + &gEfiRegularExpressionProtocolGuid, + (VOID**)&RegularExpressionProtocol + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + RegExSyntaxTypeListSize = 0; + RegExSyntaxTypeList = NULL; + + Status = RegularExpressionProtocol->GetInfo ( + RegularExpressionProtocol, + &RegExSyntaxTypeListSize, + RegExSyntaxTypeList + ); + if (Status == EFI_BUFFER_TOO_SMALL) { + RegExSyntaxTypeList = AllocateZeroPool(RegExSyntaxTypeListSize); + if (RegExSyntaxTypeList == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + Status = RegularExpressionProtocol->GetInfo ( + RegularExpressionProtocol, + &RegExSyntaxTypeListSize, + RegExSyntaxTypeList + ); + } else if (EFI_ERROR (Status)) { + goto Done; + } + + for (GuidIndex = 0; GuidIndex < RegExSyntaxTypeListSize / sizeof(EFI_GUID); GuidIndex++) { + if (CompareGuid (&RegExSyntaxTypeList[GuidIndex], SyntaxType)) { + // + // Find the match type, return the value. + // + Result->Type = EFI_IFR_TYPE_BOOLEAN; + Status = RegularExpressionProtocol->MatchString ( + RegularExpressionProtocol, + String[0], + String[1], + SyntaxType, + &Result->Value.b, + NULL, + &CapturesCount + ); + goto Done; + } + } + + if (RegExSyntaxTypeList != NULL) { + FreePool (RegExSyntaxTypeList); + } + } + + // + // Type specified by SyntaxType is not supported + // in any of the EFI_REGULAR_EXPRESSION_PROTOCOL instances. + // + Value->Type = EFI_IFR_TYPE_UNDEFINED; + Status = EFI_SUCCESS; + +Done: + if (String[0] != NULL) { + FreePool (String[0]); + } + if (String[1] != NULL) { + FreePool (String[1]); + } + if (RegExSyntaxTypeList != NULL) { + FreePool (RegExSyntaxTypeList); + } + if (HandleBuffer != NULL) { + FreePool (HandleBuffer); + } + return Status; +} /** Evaluate opcode EFI_IFR_FIND. @@ -3267,6 +3438,10 @@ EvaluateExpression ( Status = IfrMatch (FormSet, Value); break; + case EFI_IFR_MATCH2_OP: + Status = IfrMatch2 (FormSet, &OpCode->Guid, Value); + break; + case EFI_IFR_CATENATE_OP: Status = IfrCatenate (FormSet, Value); break; diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c b/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c index 7b77634973..8ddc449e69 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c @@ -1152,7 +1152,8 @@ IsExpressionOpCode ( (Operand == EFI_IFR_TO_UPPER_OP) || (Operand == EFI_IFR_MAP_OP) || (Operand == EFI_IFR_VERSION_OP) || - (Operand == EFI_IFR_SECURITY_OP)) { + (Operand == EFI_IFR_SECURITY_OP) || + (Operand == EFI_IFR_MATCH2_OP)) { return TRUE; } else { return FALSE; @@ -1207,7 +1208,7 @@ IsUnKnownOpCode ( IN UINT8 Operand ) { - return Operand > EFI_IFR_WARNING_IF_OP ? TRUE : FALSE; + return Operand > EFI_IFR_MATCH2_OP ? TRUE : FALSE; } /** @@ -1479,6 +1480,10 @@ ParseOpCodes ( CopyMem (&ExpressionOpCode->Guid, &((EFI_IFR_SECURITY *) OpCodeData)->Permissions, sizeof (EFI_GUID)); break; + case EFI_IFR_MATCH2_OP: + CopyMem (&ExpressionOpCode->Guid, &((EFI_IFR_MATCH2 *) OpCodeData)->SyntaxType, sizeof (EFI_GUID)); + break; + case EFI_IFR_GET_OP: case EFI_IFR_SET_OP: CopyMem (&TempVarstoreId, &((EFI_IFR_GET *) OpCodeData)->VarStoreId, sizeof (TempVarstoreId)); diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h index 0a935e80af..8fabf6f3c6 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h @@ -32,6 +32,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf b/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf index d7b537febc..08f71f3e59 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf +++ b/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf @@ -3,7 +3,7 @@ # # It also produces FormBrowserEx(2) protocol to let user register the different Hot key service. # -# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -75,6 +75,7 @@ ## NOTIFY gEdkiiFormDisplayEngineProtocolGuid gEfiFormBrowserExProtocolGuid ## PRODUCES + gEfiRegularExpressionProtocolGuid ## CONSUMES [FeaturePcd] gEfiMdeModulePkgTokenSpaceGuid.PcdFrameworkCompatibilitySupport ## CONSUMES