From 21173ac15231e49686026d6c209b7d5e11ab7546 Mon Sep 17 00:00:00 2001 From: Mike Turner Date: Fri, 28 Dec 2018 00:54:22 +0000 Subject: [PATCH] Merged PR 613: Minor cleanup and add Virutaliztion setting (limited) Misspelling, line end blanks, and add a settings manager for DFCI Virtualization Settings --- DfciPkg/Application/DfciMenu/DfciMenu.c | 29 +- DfciPkg/Application/DfciMenu/DfciMenu.h | 1 + DfciPkg/Application/DfciMenu/DfciMenu.inf | 1 + .../Application/DfciMenu/DfciMenuStrings.uni | 4 +- DfciPkg/Application/DfciMenu/DfciMenuVfr.Vfr | 26 +- DfciPkg/DfciPkg.dsc | 3 + .../DfciSettingPermission.c | 13 +- .../DfciVirtualizationSettings.c | 437 ++++++++++++++++++ .../DfciVirtualizationSettings.inf | 76 +++ .../SettingsManagerProvisionedData.c | 14 +- .../SettingsManagerTransportXml.c | 10 +- 11 files changed, 574 insertions(+), 40 deletions(-) create mode 100644 DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.c create mode 100644 DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.inf diff --git a/DfciPkg/Application/DfciMenu/DfciMenu.c b/DfciPkg/Application/DfciMenu/DfciMenu.c index e8b02063aa..67b1c45065 100644 --- a/DfciPkg/Application/DfciMenu/DfciMenu.c +++ b/DfciPkg/Application/DfciMenu/DfciMenu.c @@ -519,7 +519,7 @@ GetDfciParameters ( Status = GetASetting (DFCI_SETTING_ID__MDM_TENANT_NAME, &Name, &NameSize); if (!EFI_ERROR(Status) && (NameSize >= 1)) { - mDfciMenuConfiguration.DfciFriendlyName = TRUE; + mDfciMenuConfiguration.DfciTennantName = TRUE; SetStringEntry (STRING_TOKEN(STR_DFCI_MDM_TENANT_NAME), Name); DEBUG((DEBUG_INFO, "Dfci MDM.Tenant is enabled\n")); } @@ -643,8 +643,9 @@ DfciMenuEntry( STATIC EFI_STATUS DisplayMessageBox ( + EFI_STRING_ID MsgToken, IN EFI_STATUS StatusIn, - IN CHAR16 *MessageText + IN CHAR16 *MessageText OPTIONAL ) { UINT32 MessageBoxType; @@ -656,10 +657,6 @@ DisplayMessageBox ( DFCI_MB_RESULT SwmResult; - if (NULL == MessageText) { - return EFI_INVALID_PARAMETER; - } - MessageBoxType = DFCI_MB_OK; SwmResult = DFCI_MB_IDOK; pTitle = HiiGetString(mDfciMenuPrivate.HiiHandle, STRING_TOKEN(STR_DFCI_MB_TITLE), NULL); @@ -672,8 +669,8 @@ DisplayMessageBox ( } pCaption = HiiGetString(mDfciMenuPrivate.HiiHandle, STRING_TOKEN(STR_DFCI_MB_CAPTION), NULL); - pBody = HiiGetString(mDfciMenuPrivate.HiiHandle, STRING_TOKEN(STR_DFCI_MB_NEW_SETTINGS), NULL); - if (NULL != pBody) { + pBody = HiiGetString(mDfciMenuPrivate.HiiHandle, MsgToken, NULL); + if ((NULL != pBody) && (NULL != MessageText)) { pTmp = AllocatePool(MAX_MSG_SIZE); if (NULL != pTmp) { UnicodeSPrint(pTmp, MAX_MSG_SIZE, pBody, MessageText); @@ -687,7 +684,7 @@ DisplayMessageBox ( case EFI_NOT_FOUND: pBody = HiiGetString(mDfciMenuPrivate.HiiHandle, STRING_TOKEN(STR_DFCI_MB_NOT_FOUND), NULL); - if (NULL != pBody) { + if ((NULL != pBody) && (NULL != MessageText)) { pTmp = AllocatePool(MAX_MSG_SIZE); if (NULL != pTmp) { UnicodeSPrint(pTmp, MAX_MSG_SIZE, pBody, MessageText); @@ -773,6 +770,10 @@ IssueDfciNetworkRequest ( // EfiEventGroupSignal (&gDfciConfigStartEventGroupGuid); + // Platform Late Locking event. For now, just signal + // ReadyToBoot(). + EfiEventGroupSignal (&gEfiEventPreReadyToBootGuid); + JsonString = NULL; DfciIdString = NULL; // @@ -812,7 +813,7 @@ IssueDfciNetworkRequest ( // Url = ConvertToCHAR16 (mDfciUrl); - DisplayMessageBox (Status, Url); + DisplayMessageBox (STRING_TOKEN(STR_DFCI_MB_NEW_SETTINGS), Status, Url); if (NULL != Url) { FreePool (Url); @@ -844,6 +845,10 @@ IssueDfciUsbRequest ( // EfiEventGroupSignal (&gDfciConfigStartEventGroupGuid); + // Platform Late Locking event. For now, just signal + // ReadyToBoot(). + EfiEventGroupSignal (&gEfiEventPreReadyToBootGuid); + FileName = NULL; JsonString = NULL; @@ -889,7 +894,7 @@ IssueDfciUsbRequest ( // // Inform user that operation is complete // - DisplayMessageBox (Status, FileName); + DisplayMessageBox (STRING_TOKEN(STR_DFCI_MB_NEW_SETTINGS), Status, FileName); if (NULL != JsonString) { FreePool (JsonString); @@ -995,6 +1000,7 @@ DriverCallback ( *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; Status = EFI_SUCCESS; + DisplayMessageBox (STRING_TOKEN(STR_DFCI_MB_OPT_CHANGE), Status, NULL); break; case DFCI_MENU_ZUM_OPT_OUT_QUESTION_ID: @@ -1005,6 +1011,7 @@ DriverCallback ( *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; Status = EFI_SUCCESS; + DisplayMessageBox (STRING_TOKEN(STR_DFCI_MB_OPT_CHANGE), Status, NULL); break; default: diff --git a/DfciPkg/Application/DfciMenu/DfciMenu.h b/DfciPkg/Application/DfciMenu/DfciMenu.h index 81e9f2e55e..7957c4ddd8 100644 --- a/DfciPkg/Application/DfciMenu/DfciMenu.h +++ b/DfciPkg/Application/DfciMenu/DfciMenu.h @@ -72,6 +72,7 @@ typedef struct { UINT8 DfciUser1Enabled; UINT8 DfciUser2Enabled; UINT8 DfciFriendlyName; + UINT8 DfciTennantName; UINT8 DfciOptInChanged; } DFCI_MENU_CONFIGURATION; diff --git a/DfciPkg/Application/DfciMenu/DfciMenu.inf b/DfciPkg/Application/DfciMenu/DfciMenu.inf index cf1aae734c..4c4c986c75 100644 --- a/DfciPkg/Application/DfciMenu/DfciMenu.inf +++ b/DfciPkg/Application/DfciMenu/DfciMenu.inf @@ -95,6 +95,7 @@ gDfciSettingsGuid gDfciSettingsManagerVarNamespace gEfiBootManagerPolicyNetworkGuid + gEfiEventPreReadyToBootGuid [Protocols] gDfciAuthenticationProtocolGuid diff --git a/DfciPkg/Application/DfciMenu/DfciMenuStrings.uni b/DfciPkg/Application/DfciMenu/DfciMenuStrings.uni index 0766326b58..8705042371 100644 --- a/DfciPkg/Application/DfciMenu/DfciMenuStrings.uni +++ b/DfciPkg/Application/DfciMenu/DfciMenuStrings.uni @@ -144,4 +144,6 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #string STR_DFCI_MB_NOT_FOUND #language en-US "%s not found." -#string STR_DFCI_MB_INTERNAL_ERROR #language en-US "Internal error. Code=%r." \ No newline at end of file +#string STR_DFCI_MB_INTERNAL_ERROR #language en-US "Internal error. Code=%r." + +#string STR_DFCI_MB_OPT_CHANGE #language en-US "ZTD Opt In changed. Restart now to apply the change." \ No newline at end of file diff --git a/DfciPkg/Application/DfciMenu/DfciMenuVfr.Vfr b/DfciPkg/Application/DfciMenu/DfciMenuVfr.Vfr index 7a58f2dded..6214a807ce 100644 --- a/DfciPkg/Application/DfciMenu/DfciMenuVfr.Vfr +++ b/DfciPkg/Application/DfciMenu/DfciMenuVfr.Vfr @@ -160,28 +160,32 @@ formset help = STRING_TOKEN(STR_NULL_STRING), // Subject: text = STRING_TOKEN(STR_DFCI_MANAGED_BY); - suppressif ideqval DfciMenuConfig.DfciFriendlyName == 0x00; // If no friendly name, just + suppressif NOT ideqval DfciMenuConfig.DfciFriendlyName == 0x00; // If no friendly name, just text help = STRING_TOKEN(STR_NULL_STRING), // managed by owner text = STRING_TOKEN(STR_DFCI_OWNER_SUBJECT_FIELD); endif; - suppressif NOT ideqval DfciMenuConfig.DfciFriendlyName == 0x00; // If friendly name, + suppressif ideqval DfciMenuConfig.DfciFriendlyName == 0x00; // If friendly name, text help = STRING_TOKEN(STR_NULL_STRING), // managed by MDM text = STRING_TOKEN(STR_DFCI_MDM_FRIENDLY_NAME); - subtitle - text = STRING_TOKEN(STR_NULL_STRING), // Group of horizontal text blocks - flags = HORIZONTAL; + suppressif ideqval DfciMenuConfig.DfciTennantName == 0x00; // If Tennant Name name, - text - help = STRING_TOKEN(STR_NULL_STRING), // On behalf of MDM Tenant name - text = STRING_TOKEN(STR_DFCI_ON_BEHALF_OF); + subtitle + text = STRING_TOKEN(STR_NULL_STRING), // Group of horizontal text blocks + flags = HORIZONTAL; + + text + help = STRING_TOKEN(STR_NULL_STRING), // On behalf of MDM Tenant name + text = STRING_TOKEN(STR_DFCI_ON_BEHALF_OF); + + text + help = STRING_TOKEN(STR_NULL_STRING), + text = STRING_TOKEN(STR_DFCI_MDM_TENANT_NAME); + endif; - text - help = STRING_TOKEN(STR_NULL_STRING), - text = STRING_TOKEN(STR_DFCI_MDM_TENANT_NAME); endif; text diff --git a/DfciPkg/DfciPkg.dsc b/DfciPkg/DfciPkg.dsc index 4d29a54d69..ed7f832588 100644 --- a/DfciPkg/DfciPkg.dsc +++ b/DfciPkg/DfciPkg.dsc @@ -90,6 +90,7 @@ DfciUiSupportLib|DfciPkg/Library/DfciUiSupportLibNull/DfciUiSupportLibNull.inf DfciV1SupportLib|DfciPkg/Library/DfciV1SupportLibNull/DfciV1SupportLibNull.inf DfciSettingsLib|DfciPkg/Library/DfciSettingsLib/DfciSettingsLib.inf + DfciVirtualizationSettingsLib|DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.inf ZeroTouchSettingsLib|ZeroTouchPkg/Library/ZeroTouchSettings/ZeroTouchSettings.inf JsonLiteParserLib|MsCorePkg/Library/JsonLiteParser/JsonLiteParser.inf @@ -162,11 +163,13 @@ DfciPkg/Library/DfciXmlSettingSchemaSupportLib/DfciXmlSettingSchemaSupportLib.inf DfciPkg/Library/DfciXmlDeviceIdSchemaSupportLib/DfciXmlDeviceIdSchemaSupportLib.inf DfciPkg/Library/DfciXmlIdentitySchemaSupportLib/DfciXmlIdentitySchemaSupportLib.inf + DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.inf DfciPkg/SettingsManager/SettingsManagerDxe.inf { #Platform should add all it settings libs here NULL|DfciPkg/Library/DfciSettingsLib/DfciSettingsLib.inf + NULL|DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.inf DfciSettingPermissionLib|DfciPkg/Library/DfciSettingPermissionLib/DfciSettingPermissionLib.inf gDfciPkgTokenSpaceGuid.PcdSettingsManagerInstallProvider|TRUE diff --git a/DfciPkg/Library/DfciSettingPermissionLib/DfciSettingPermission.c b/DfciPkg/Library/DfciSettingPermissionLib/DfciSettingPermission.c index ed1701359e..d8ee9eb7ec 100644 --- a/DfciPkg/Library/DfciSettingPermissionLib/DfciSettingPermission.c +++ b/DfciPkg/Library/DfciSettingPermissionLib/DfciSettingPermission.c @@ -64,7 +64,7 @@ IN CONST DFCI_AUTH_TOKEN *AuthToken OPTIONAL return EFI_NOT_READY; } - //User is trying to reset. Check if auth token is valid for this operation. + //User is trying to reset. Check if auth token is valid for this operation. // Permission is based on who can change the Owner Cert and/or who can do recovery. Status = HasWritePermissions(DFCI_SETTING_ID__OWNER_KEY, AuthToken, &CanChange); if (EFI_ERROR(Status)) @@ -86,7 +86,7 @@ IN CONST DFCI_AUTH_TOKEN *AuthToken OPTIONAL return EFI_ACCESS_DENIED; } } - + DEBUG((DEBUG_INFO, "%a - Auth Token good. Lets clear the permissions.\n", __FUNCTION__)); // 1. Free existing PermissionStore @@ -95,7 +95,7 @@ IN CONST DFCI_AUTH_TOKEN *AuthToken OPTIONAL FreePermissionStore(mPermStore); mPermStore = NULL; } - + // 2. Set it to defaults which is all access to all settings Status = InitPermStore(&mPermStore); if (EFI_ERROR(Status)) @@ -161,8 +161,7 @@ OUT BOOLEAN *Result return Status; } - - //2. set to default. + //2. set to default. PMask = mPermStore->DefaultPMask; //3. Set PMask to specific value if in list @@ -278,13 +277,15 @@ IdentityChange ( Status = AddRequiredPermissionEntry (mPermStore, DFCI_SETTING_ID__ZTD_KEY, DFCI_IDENTITY_INVALID, DFCI_PERMISSION_MASK__NONE); } - // 4. When an Owner is entrolled and the signer is ZTD: + // 4. When an Owner is enrolled and the signer is ZTD: if (Properties.Identity == DFCI_IDENTITY_SIGNER_ZTD) { // a. Allow ZTD to UnEnroll. // b. Allow ZTD to use hard reset Recovery + // c. Remove SEMM recovery permission Status |= AddRequiredPermissionEntry (mPermStore, DFCI_SETTING_ID__ZTD_RECOVERY, DFCI_IDENTITY_SIGNER_ZTD, DFCI_PERMISSION_MASK__NONE); Status |= AddRequiredPermissionEntry (mPermStore, DFCI_SETTING_ID__ZTD_UNENROLL, DFCI_IDENTITY_SIGNER_ZTD, DFCI_PERMISSION_MASK__NONE); + Status |= AddRequiredPermissionEntry (mPermStore, DFCI_SETTING_ID__DFCI_RECOVERY, DFCI_PERMISSION_MASK__NONE, DFCI_PERMISSION_MASK__NONE); return EFI_SUCCESS; } diff --git a/DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.c b/DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.c new file mode 100644 index 0000000000..d75183c706 --- /dev/null +++ b/DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.c @@ -0,0 +1,437 @@ +/** @file +DfciSettings.c + +Library Instance for DXE to support getting, setting, defaults, and support the +Dfci.CpuAndIoVirtualization.Enable setting. + +Copyright (c) 2018, Microsoft Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include + +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +EFI_EVENT mDfciSettingsProviderSupportInstallEvent; +VOID *mDfciSettingsProviderSupportInstallEventRegistration = NULL; + +typedef enum { + ID_IS_BAD, + ID_IS_VIRTUALIZATION, +} ID_IS; + +// There are no setting to change the support for CPU and I/O virtualization + +#define HARD_CODED_VIRTUALIZAION 1 + +// Forward declarations needed +/** + * Settings Provider GetDefault routine + * + * @param This + * @param ValueSize + * @param Value + * + * @return EFI_STATUS EFIAPI + */ +STATIC +EFI_STATUS +EFIAPI +DfciSettingsGetDefault ( + IN CONST DFCI_SETTING_PROVIDER *This, + IN OUT UINTN *ValueSize, + OUT VOID *Value + ); + +/** + * Settings Provider Get routine + * + * @param This + * @param ValueSize + * @param Value + * + * @return EFI_STATUS EFIAPI + */ +STATIC +EFI_STATUS +EFIAPI +DfciSettingsGet ( + IN CONST DFCI_SETTING_PROVIDER *This, + IN OUT UINTN *ValueSize, + OUT VOID *Value + ); + +/** +@param Id - Setting ID to check for support status +@retval ID_IS_xx - of the supported settings +@retval ID_IS_BAD - Not supported +**/ +STATIC +ID_IS +IsIdSupported ( + IN DFCI_SETTING_ID_STRING Id + ) { + + if (0 == AsciiStrnCmp (Id, DFCI_SETTING_ID__ALL_CPU_IO_VIRT, DFCI_MAX_ID_LEN)) { + return ID_IS_VIRTUALIZATION; + } else { + DEBUG((DEBUG_ERROR, "%a: Called with Invalid ID (%a)\n", __FUNCTION__, Id)); + } + + return ID_IS_BAD; +} + +/////---------------------Interface for Settings Provider ---------------------////// + +/** + * Settings Provider Set Routine + * + * @param This + * @param ValueSize + * @param Value + * @param Flags + * + * @return EFI_STATUS EFIAPI + */ +STATIC +EFI_STATUS +EFIAPI +DfciSettingsSet ( + IN CONST DFCI_SETTING_PROVIDER *This, + IN UINTN ValueSize, + IN CONST VOID *Value, + OUT DFCI_SETTING_FLAGS *Flags + ) { + + EFI_STATUS Status; + ID_IS Id; + UINT8 NewValue; + + if ((This == NULL) || (This->Id == NULL) || (Value == NULL) || (Flags == NULL) || (ValueSize < sizeof(UINT8))) { + DEBUG((DEBUG_ERROR, "%a: Invalid parameter.\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + NewValue = *((UINT8 *) Value); + + Id = IsIdSupported(This->Id); + switch (Id) { + case ID_IS_VIRTUALIZATION: + if (NewValue != HARD_CODED_VIRTUALIZAION) { + Status = EFI_ACCESS_DENIED; + } else { + *Flags |= DFCI_SETTING_FLAGS_OUT_ALREADY_SET; + Status = EFI_SUCCESS; + } + break; + + default: + DEBUG((DEBUG_ERROR, "%a: Invalid id(%s).\n", __FUNCTION__, This->Id)); + Status = EFI_UNSUPPORTED; + break; + } + + return Status; +} + +/** + * Settings Provider Get routine + * + * @param This + * @param ValueSize + * @param Value + * + * @return EFI_STATUS EFIAPI + */ +STATIC +EFI_STATUS +EFIAPI +DfciSettingsGet ( + IN CONST DFCI_SETTING_PROVIDER *This, + IN OUT UINTN *ValueSize, + OUT VOID *Value + ) { + + ID_IS Id; + EFI_STATUS Status; + CHAR8 *CurrentValue; + + if ((This == NULL) || (This->Id == NULL) || (ValueSize == NULL) || (Value == NULL)) { + DEBUG((DEBUG_ERROR, "%a: Invalid parameter.\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + if (*ValueSize < sizeof(CHAR8)) { + *ValueSize = sizeof(CHAR8); + return EFI_BUFFER_TOO_SMALL; + } + + CurrentValue = (CHAR8 *) Value; + + Id = IsIdSupported(This->Id); + Status = EFI_SUCCESS; + + switch (Id) { + + // Current setting is hard coded to Enabled. + case ID_IS_VIRTUALIZATION: + *CurrentValue = HARD_CODED_VIRTUALIZAION; + *ValueSize = sizeof(CHAR8); + break; + + default: + DEBUG((DEBUG_ERROR, "%a: Invalid id(%s).\n", __FUNCTION__, This->Id)); + Status = EFI_UNSUPPORTED; + break; + } + + return Status; +} + +/** + * Settings Provider GetDefault routine + * + * @param This + * @param ValueSize + * @param Value + * + * @return EFI_STATUS EFIAPI + */ +STATIC +EFI_STATUS +EFIAPI +DfciSettingsGetDefault ( + IN CONST DFCI_SETTING_PROVIDER *This, + IN OUT UINTN *ValueSize, + OUT VOID *Value + ) { + + ID_IS Id; + CHAR8 *DefaultValue; + + if ((This == NULL) || (This->Id == NULL) || (ValueSize == NULL) || (Value == NULL)) { + DEBUG((DEBUG_ERROR, "%a: Invalid parameter.\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + if (*ValueSize < sizeof(CHAR8)) { + *ValueSize = sizeof(CHAR8); + return EFI_BUFFER_TOO_SMALL; + } + + Id = IsIdSupported(This->Id); + if (Id == ID_IS_BAD) { + return EFI_UNSUPPORTED; + } + + DefaultValue = (CHAR8 *) Value; + *ValueSize = sizeof(CHAR8); + *DefaultValue = HARD_CODED_VIRTUALIZAION; + + return EFI_SUCCESS; +} + +/** + * Settings Provider Set Default routine + * + * @param This + * + * @return EFI_STATUS EFIAPI + */ +STATIC +EFI_STATUS +EFIAPI +DfciSettingsSetDefault ( + IN CONST DFCI_SETTING_PROVIDER *This + ) { + + DFCI_SETTING_FLAGS Flags = 0; + EFI_STATUS Status; + CHAR8 Value; + UINTN ValueSize; + + if (This == NULL) { + return EFI_INVALID_PARAMETER; + } + + ValueSize = sizeof(ValueSize); + Status = DfciSettingsGetDefault (This, &ValueSize, &Value); + if (EFI_ERROR(Status)) { + return Status; + } + + return DfciSettingsSet (This, ValueSize, &Value, &Flags); +} + +// +// Since ProviderSupport Registration copies the provider to its own +// allocated memory this code can use a single "template" and just change +// the id, type, and flags field as needed for registration. +// +DFCI_SETTING_PROVIDER mDfciSettingsProviderTemplate = { + 0, + 0, + 0, + DfciSettingsSet, + DfciSettingsGet, + DfciSettingsGetDefault, + DfciSettingsSetDefault +}; + +/////---------------------Interface for Library ---------------------////// + +/** +Function to Get a Dfci Setting. +If the setting has not been previously set this function will return the default. However it will +not cause the default to be set. + +@param Id: The DFCI_SETTING_ID_ENUM of the Dfci +@param ValueSize: IN=Size Of Buffer or 0 to get size, OUT=Size of returned Value +@param Value: Ptr to a buffer for the setting to be returned. + + +@retval: Success - Setting was returned in Value +@retval: EFI_ERROR. Settings was not returned in Value. +**/ +EFI_STATUS +EFIAPI +GetVirtualizationSetting ( + IN DFCI_SETTING_ID_STRING Id, + IN OUT UINTN *ValueSize, + OUT VOID *Value + ) { + + EFI_STATUS Status; + + mDfciSettingsProviderTemplate.Id = Id; + Status = DfciSettingsGet (&mDfciSettingsProviderTemplate, ValueSize, Value); + if (EFI_ERROR(Status) && (EFI_BUFFER_TOO_SMALL != Status)) { + Status = DfciSettingsGetDefault (&mDfciSettingsProviderTemplate, ValueSize, Value); + } + return Status; +} + +/** + * Library design is such that a dependency on gDfciSettingsProviderSupportProtocolGuid + * is not desired. So to resolve that a ProtocolNotify is used. + * + * This function gets triggered once on install and 2nd time when the Protocol gets installed. + * + * When the gDfciSettingsProviderSupportProtocolGuid protocol is available the function will + * loop thru all the Dfci settings (using PCD) and install the settings + * + * Context is NULL. + * + * + * @param Event + * @param Context + * + * @return VOID EFIAPI + */ +STATIC +VOID +EFIAPI +DfciSettingsProviderSupportProtocolNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) { + + STATIC UINT8 CallCount = 0; + DFCI_SETTING_PROVIDER_SUPPORT_PROTOCOL *sp; + EFI_STATUS Status; + + //locate protocol + Status = gBS->LocateProtocol (&gDfciSettingsProviderSupportProtocolGuid, NULL, (VOID**)&sp); + if (EFI_ERROR(Status)) { + if ((CallCount++ != 0) || (Status != EFI_NOT_FOUND)) { + DEBUG((DEBUG_ERROR, "%a() - Failed to locate gDfciSettingsProviderSupportProtocolGuid in notify. Status = %r\n", __FUNCTION__, Status)); + } + return; + } + + // + // Register items that are NOT in the PREBOOT_UI + // + mDfciSettingsProviderTemplate.Id = DFCI_SETTING_ID__ALL_CPU_IO_VIRT; + mDfciSettingsProviderTemplate.Type = DFCI_SETTING_TYPE_ENABLE; + mDfciSettingsProviderTemplate.Flags = DFCI_SETTING_FLAGS_NO_PREBOOT_UI; + Status = sp->RegisterProvider (sp, &mDfciSettingsProviderTemplate); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "Failed to Register DFCI_URL. Status = %r\n", Status)); + } + + //We got here, this means all protocols were installed and we didn't exit early. + //close the event as we dont' need to be signaled again. (shouldn't happen anyway) + gBS->CloseEvent(Event); +} + +/** + * The constructor function initializes the Lib for Dxe. + * + * This constructor is only needed for DfciSettingsManager support. + * The design is to have the PCD false for all modules except the 1 anonymously liked to the DfciettingsManager. + * + * @param ImageHandle The firmware allocated handle for the EFI image. + * @param SystemTable A pointer to the EFI System Table. + * + * @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + * + **/ +EFI_STATUS +EFIAPI +DfciVirtualizationSettingsConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) { + + if (FeaturePcdGet (PcdSettingsManagerInstallProvider)) { + //Install callback on the SettingsManager gMsSystemSettingsProviderSupportProtocolGuid protocol + mDfciSettingsProviderSupportInstallEvent = EfiCreateProtocolNotifyEvent ( + &gDfciSettingsProviderSupportProtocolGuid, + TPL_CALLBACK, + DfciSettingsProviderSupportProtocolNotify, + NULL, + &mDfciSettingsProviderSupportInstallEventRegistration + ); + + DEBUG((DEBUG_INFO, "%a: Event Registered.\n", __FUNCTION__)); + } + return EFI_SUCCESS; +} \ No newline at end of file diff --git a/DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.inf b/DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.inf new file mode 100644 index 0000000000..dba31ccc2a --- /dev/null +++ b/DfciPkg/Library/DfciVirtualizationSettings/DfciVirtualizationSettings.inf @@ -0,0 +1,76 @@ +## @file +# DfciSettingsLib.inf +# +# Library to support Dfci Setting (get/set) +# +# Copyright (c) 2018, Microsoft Corporation +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +## + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = DfciVirtualizationSettingsLib + FILE_GUID = a6987668-2f26-48d6-979b-369a3b49a9a5 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = DfciVirtualizationSettingsLib | DXE_DRIVER + CONSTRUCTOR = DfciVirtualizationSettingsConstructor +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 +# + +[Sources] + DfciVirtualizationSettings.c + +[Packages] + DfciPkg/DfciPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PcdLib + UefiLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + +[Guids] + +[Protocols] + gDfciSettingsProviderSupportProtocolGuid + +[Pcd] + gDfciPkgTokenSpaceGuid.PcdSettingsManagerInstallProvider + +[Depex] + TRUE + +[BuildOptions] +# DEBUG_*_*_CC_FLAGS = /Od /FAcs + DEBUG_*_*_CC_FLAGS = /analyze diff --git a/DfciPkg/SettingsManager/SettingsManagerProvisionedData.c b/DfciPkg/SettingsManager/SettingsManagerProvisionedData.c index 960dc61949..6d247e99ea 100644 --- a/DfciPkg/SettingsManager/SettingsManagerProvisionedData.c +++ b/DfciPkg/SettingsManager/SettingsManagerProvisionedData.c @@ -37,7 +37,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define VAR_NAME L"_SMID" #define VAR_HEADER_SIG SIGNATURE_32('S', 'M', 'I', 'D') -#define VAR_VERSION (1) +#define VAR_VERSION (1) //determine min size to make sure variable is big enough to evaluate. This is headersignature plus Headerversion #define MIN_VAR_SIZE (sizeof(UINT32) + sizeof(UINT8)) @@ -108,15 +108,15 @@ SMID_TransitionInternalVariableData( goto Exit; } - //Basically get version and transition + //Basically get version and transition //Need to free the original var after done copying //Need to update the varsize to match new size - // At the moment we don't have more than 1 version so this should never happen + // At the moment we don't have more than 1 version so this should never happen DEBUG((DEBUG_ERROR, "%a - Unsupported Version. No conversion method set. 0x%X\n", __FUNCTION__, (*VarPtr)->Version)); Status = EFI_UNSUPPORTED; -Exit: +Exit: ASSERT_EFI_ERROR(Status); return Status; } @@ -279,7 +279,7 @@ SMID_SaveToFlash(IN DFCI_SETTING_INTERNAL_DATA *InternalData) DEBUG((DEBUG_INFO, "%a - Not Modified. No action needed.\n", __FUNCTION__)); return EFI_SUCCESS; } - + VarSize = sizeof(DFCI_INTERNAL_DATA_VAR); Var = (DFCI_INTERNAL_DATA_VAR *)AllocateZeroPool(VarSize); if (Var == NULL) @@ -330,10 +330,10 @@ SMID_ResetInFlash() Status = gRT->SetVariable(VAR_NAME, &gDfciInternalVariableGuid, DFCI_INTERNAL_VAR_ATTRIBUTES, 0, NULL); if (Status == EFI_NOT_FOUND) { - //Special case for not found. If var doesn't exist then our job has been done successfully. + //Special case for not found. If var doesn't exist then our job has been done successfully. Status = EFI_SUCCESS; } - + if (EFI_ERROR(Status)) { DEBUG((DEBUG_ERROR, "%a - failed to Reset the internal data variable. Status %r\n", __FUNCTION__, Status)); diff --git a/DfciPkg/SettingsManager/SettingsManagerTransportXml.c b/DfciPkg/SettingsManager/SettingsManagerTransportXml.c index 61f98e3016..2f833304af 100644 --- a/DfciPkg/SettingsManager/SettingsManagerTransportXml.c +++ b/DfciPkg/SettingsManager/SettingsManagerTransportXml.c @@ -1,7 +1,7 @@ /**@file SettingsManagerTransportXml.c -Thsi file supports the tool input path for setting settings. +This file supports the tool input path for setting settings. Settings are set using XML. That xml is written to a variable and then passed to UEFI to be applied. This code supports that. @@ -449,7 +449,7 @@ FreeSettings( // // Free locally allocated memory -// -- this function only gets called when system is not resetting. +// -- this function only gets called when system is not resetting. // VOID EFIAPI @@ -572,7 +572,7 @@ ApplyNewSettingsPacket ( DEBUG((DEBUG_ERROR, "%a - Failed to load Settings Manager Internal Data. %r\n", __FUNCTION__, Status)); } - //If load failed - init store + //If load failed - init store Status = SMID_InitInternalData(&InternalData); if (EFI_ERROR(Status)) { @@ -601,7 +601,9 @@ ApplyNewSettingsPacket ( ClearCacheOfCurrentSettings(); CLEANUP: - UpdateSettingsResult(Data, InternalData); + if (InternalData != NULL) { + UpdateSettingsResult(Data, InternalData); + } FreeSettings(Data); AuthTokenDispose(&Data->AuthToken); FreeInstanceMemory(Data, &InternalData);