From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mx.groups.io with SMTP id smtpd.web11.5165.1686257080958803475 for ; Thu, 08 Jun 2023 13:44:41 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=f9zSBgxG; spf=pass (domain: gmail.com, ip: 209.85.210.172, mailfrom: kuqin12@gmail.com) Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-64d44b198baso822058b3a.0 for ; Thu, 08 Jun 2023 13:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686257080; x=1688849080; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dBfjQFNdNe7ia8qgS5lhFxywQfwuOR/30luBJ4efk20=; b=f9zSBgxGiJjEy8e3yrScNexeIxWhKl77eAx+F1piHXLMMY1omCbzXw5rseflbmTekC D9P5doqpMA+lMHEm9ONAEwJ2DFkBklkcNt39w96NzzSt1NZd9uF0iyy5PEphph1h+9an 7DF+ev46oeC38n/857kO4CvqdiZImeZ7yCfJRnaQWRXm0P/vnOBG4caQwos6+Z3Z+WaG dGmY9YeT6CKK4CFxR0mrmo5tE+6jguQtgJLhp67OdiXGiualEJY+Q7QYy+eo7wJjd+xX SqGc1H5E71fKnWy5WlBTO6Gz9qyv/bul3OcGewzWZLmpQ21fSp0fdoEUsv7r+0VlN3Ak dIhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686257080; x=1688849080; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dBfjQFNdNe7ia8qgS5lhFxywQfwuOR/30luBJ4efk20=; b=k/hjQY1rPQyhjAXC1NH3DIpbqrpH4gctMPdsLH0vRwUoI5BBbeYrqEbJZJw8gL9bQV TkHZ7fNxMOkW7NGM371HkQVS31bCGseK3lJc+++sI+8NqW/a1gaDydMN114JPu8S9oQu b/AZTZx9OvKH7E0ay32gPdedmJyb+2MO62fkVx8H7IIjyW3kbRw7Q21bDUh+jgdH6ybG 0u8RnEFIzplLZ7CC5/WrNi2Or8eTAMp65LhlYqwkbStsAIUuopnRwA9GeZfbRvj/BLBI zpSnZ9jrzaezTapU+AoV0fzrDHRtNuJS0i9cMbge3YN4OlYSKJnL/pUkM7x+c9MnqUo4 rtAg== X-Gm-Message-State: AC+VfDwdkyCcQz6xJLUGfFKTESHNxFk179SdU/eld534UEOjzZaR6K/d wApqOlYeQ+VKrzDO1SUv1rHgz1baAUw= X-Google-Smtp-Source: ACHHUZ7dy82Y+aIE95EQJx+AzV4dFrbBtKN+WbGrrHxdmveikq131Goalmpqu8g1YNO0pYLhGZ5jtA== X-Received: by 2002:a05:6a20:394b:b0:10c:2c30:4765 with SMTP id r11-20020a056a20394b00b0010c2c304765mr3848252pzg.1.1686257080020; Thu, 08 Jun 2023 13:44:40 -0700 (PDT) Return-Path: Received: from MININT-0U7P5GU.redmond.corp.microsoft.com ([2001:4898:80e8:2:fc6a:9362:be2c:efe5]) by smtp.gmail.com with ESMTPSA id k15-20020aa7820f000000b0065e279c5c2csm1450767pfi.181.2023.06.08.13.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 13:44:39 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Hao A Wu , Liming Gao , Jian J Wang , Ronny Hansen , Shriram Masanamuthu Chinnathurai , Preshit Harlikar Subject: [PATCH v1 2/2] MdeModulePkg: Variable: Introduce MM based variable read service in PEI Date: Thu, 8 Jun 2023 13:44:34 -0700 Message-Id: <20230608204434.2325-3-kuqin12@gmail.com> X-Mailer: git-send-email 2.40.1.windows.1 In-Reply-To: <20230608204434.2325-1-kuqin12@gmail.com> References: <20230608204434.2325-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Kun Qin REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4464 This change introduced the Standalone MM based variable read capability in PEI phase for applicable platforms (such as ARM platforms). Similar to the x86 counterpart, MM communicate PPI is used to request variable information from Standalone MM environment. Cc: Hao A Wu Cc: Liming Gao Cc: Jian J Wang Co-authored-by: Ronny Hansen Co-authored-by: Shriram Masanamuthu Chinnathurai Co-authored-by: Preshit Harlikar Signed-off-by: Kun Qin --- MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c | 381 ++++= ++++++++++++++++ MdeModulePkg/MdeModulePkg.dsc | 1 + MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h | 134 ++++= +++ MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf | 43 +++ 4 files changed, 559 insertions(+) diff --git a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c = b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c new file mode 100644 index 000000000000..4f937e22e89e --- /dev/null +++ b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c @@ -0,0 +1,381 @@ +/** @file -- MmVariablePei.c=0D + Provides interface for reading Secure System Variables during PEI.=0D +=0D + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
=0D + Copyright (c) Microsoft Corporation.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#include "MmVariablePei.h"=0D +=0D +#define MM_VARIABLE_COMM_BUFFER_OFFSET (SMM_COMMUNICATE_HEADER_SIZE + SMM= _VARIABLE_COMMUNICATE_HEADER_SIZE)=0D +=0D +//=0D +// Module globals=0D +//=0D +EFI_PEI_READ_ONLY_VARIABLE2_PPI mPeiSecureVariableRead =3D {=0D + PeiMmGetVariable,=0D + PeiMmGetNextVariableName=0D +};=0D +=0D +EFI_PEI_PPI_DESCRIPTOR mPeiMmVariablePpi =3D {=0D + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),=0D + &gEfiPeiReadOnlyVariable2PpiGuid,=0D + &mPeiSecureVariableRead=0D +};=0D +=0D +/**=0D + Entry point of PEI Secure Variable read driver=0D +=0D + @param FileHandle Handle of the file being invoked.=0D + Type EFI_PEI_FILE_HANDLE is defined in FfsFindNextF= ile().=0D + @param PeiServices General purpose services available to every PEIM.=0D +=0D + @retval EFI_SUCCESS If the interface could be successfully installed=0D + @retval Others Returned from PeiServicesInstallPpi()=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiMmVariableInitialize (=0D + IN EFI_PEI_FILE_HANDLE FileHandle,=0D + IN CONST EFI_PEI_SERVICES **PeiServices=0D + )=0D +{=0D + return PeiServicesInstallPpi (&mPeiMmVariablePpi);=0D +}=0D +=0D +/**=0D + Helper function to populate MM communicate header and variable communica= te header=0D + and then communicate to PEI.=0D +=0D + @param[in, out] CommunicateBuffer Size of the variable name.=0D + @param[in] CommunicateBufferSize The entire buffer size to be sen= t to MM.=0D + @param[in] Function The MM variable function value.= =0D +=0D + @retval EFI_INVALID_PARAMETER Invalid parameter.=0D + @retval EFI_SUCCESS Find the specified variable.=0D + @retval Others Errors returned by MM communicate or = variable service.=0D +=0D +**/=0D +EFI_STATUS=0D +PopulateHeaderAndCommunicate (=0D + IN OUT UINT8 *CommunicateBuffer,=0D + IN UINTN CommunicateBufferSize,=0D + IN UINTN Function=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_PEI_MM_COMMUNICATION_PPI *MmCommunicationPpi;=0D + EFI_MM_COMMUNICATE_HEADER *MmCommunicateHeader;=0D + SMM_VARIABLE_COMMUNICATE_HEADER *MmVarCommsHeader;=0D +=0D + // Minimal sanity check=0D + if ((CommunicateBuffer =3D=3D NULL) ||=0D + (CommunicateBufferSize < MM_VARIABLE_COMM_BUFFER_OFFSET))=0D + {=0D + Status =3D EFI_INVALID_PARAMETER;=0D + DEBUG ((DEBUG_ERROR, "%a: Invalid incoming parameters: %p and 0x%x\n",= __func__, CommunicateBuffer, CommunicateBufferSize));=0D + goto Exit;=0D + }=0D +=0D + if ((Function !=3D SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME) &&=0D + (Function !=3D SMM_VARIABLE_FUNCTION_GET_VARIABLE))=0D + {=0D + Status =3D EFI_INVALID_PARAMETER;=0D + DEBUG ((DEBUG_ERROR, "%a: Invalid function value: 0x%x\n", __func__, F= unction));=0D + goto Exit;=0D + }=0D +=0D + Status =3D PeiServicesLocatePpi (&gEfiPeiMmCommunicationPpiGuid, 0, NULL= , (VOID **)&MmCommunicationPpi);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "%a: Failed to locate PEI MM Communication PPI: %= r\n", __func__, Status));=0D + goto Exit;=0D + }=0D +=0D + // Zero the entire Communication Buffer Header=0D + MmCommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER *)CommunicateBuffer;= =0D +=0D + ZeroMem (MmCommunicateHeader, SMM_COMMUNICATE_HEADER_SIZE);=0D +=0D + // Use gEfiSmmVariableProtocolGuid to request the MM variable service in= Standalone MM=0D + CopyMem ((VOID *)&MmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProto= colGuid, sizeof (GUID));=0D +=0D + // Program the MM header size=0D + MmCommunicateHeader->MessageLength =3D CommunicateBufferSize - SMM_COMMU= NICATE_HEADER_SIZE;=0D +=0D + MmVarCommsHeader =3D (SMM_VARIABLE_COMMUNICATE_HEADER *)(CommunicateBuff= er + SMM_COMMUNICATE_HEADER_SIZE);=0D +=0D + // We are only supporting GetVariable and GetNextVariableName=0D + MmVarCommsHeader->Function =3D Function;=0D +=0D + // Send the MM request using MmCommunicationPei=0D + Status =3D MmCommunicationPpi->Communicate (MmCommunicationPpi, Communic= ateBuffer, &CommunicateBufferSize);=0D + if (EFI_ERROR (Status)) {=0D + // Received an error from MM interface.=0D + DEBUG ((DEBUG_ERROR, "%a - MM Interface Error: %r\n", __func__, Status= ));=0D + goto Exit;=0D + }=0D +=0D + // MM request was successfully handled by the framework.=0D + // Set status to the Variable Service Status Code=0D + Status =3D MmVarCommsHeader->ReturnStatus;=0D + if (EFI_ERROR (Status)) {=0D + // We received an error from Variable Service.=0D + // We cant do anymore so return Status=0D + if (Status !=3D EFI_BUFFER_TOO_SMALL) {=0D + DEBUG ((DEBUG_ERROR, "%a - Variable Service Error: %r\n", __func__, = Status));=0D + }=0D +=0D + goto Exit;=0D + }=0D +=0D +Exit:=0D + return Status;=0D +}=0D +=0D +/**=0D + This service retrieves a variable's value using its name and GUID.=0D +=0D + This function is using the Secure Variable Store. If the Data=0D + buffer is too small to hold the contents of the variable, the error=0D + EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the required buf= fer=0D + size to obtain the data.=0D +=0D + @param This A pointer to this instance of the EFI_PEI_= READ_ONLY_VARIABLE2_PPI.=0D + @param VariableName A pointer to a null-terminated string that= is the variable's name.=0D + @param VariableGuid A pointer to an EFI_GUID that is the varia= ble's GUID. The combination of=0D + VariableGuid and VariableName must be uniq= ue.=0D + @param Attributes If non-NULL, on return, points to the vari= able's attributes.=0D + @param DataSize On entry, points to the size in bytes of t= he Data buffer.=0D + On return, points to the size of the data = returned in Data.=0D + @param Data Points to the buffer which will hold the r= eturned variable value.=0D + May be NULL with a zero DataSize in order = to determine the size of the buffer needed.=0D +=0D + @retval EFI_SUCCESS The variable was read successfully.=0D + @retval EFI_NOT_FOUND The variable was not found.=0D + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the resultin= g data.=0D + DataSize is updated with the size required= for=0D + the specified variable.=0D + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid, DataSize or Da= ta is NULL.=0D + @retval EFI_DEVICE_ERROR The variable could not be retrieved becaus= e of a device error.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiMmGetVariable (=0D + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,=0D + IN CONST CHAR16 *VariableName,=0D + IN CONST EFI_GUID *VariableGuid,=0D + OUT UINT32 *Attributes, OPTIONAL=0D + IN OUT UINTN *DataSize,=0D + OUT VOID *Data OPTIONAL=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINTN MessageSize;=0D + SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *MmVarAccessHeader;=0D + UINT8 *MmCommunicateBuffer;=0D + UINTN RequiredPages;=0D +=0D + // Check input parameters=0D + if ((VariableName =3D=3D NULL) || (VariableGuid =3D=3D NULL) || (DataSiz= e =3D=3D NULL)) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + if (VariableName[0] =3D=3D 0) {=0D + return EFI_NOT_FOUND;=0D + }=0D +=0D + if ((*DataSize > 0) && (Data =3D=3D NULL)) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + // Allocate required pages to send MM request=0D + MessageSize =3D MM_VARIABLE_COMM_BUFFER_OFFSET +=0D + OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)= +=0D + StrSize (VariableName) + *DataSize;=0D +=0D + RequiredPages =3D EFI_SIZE_TO_PAGES (MessageSize);=0D + MmCommunicateBuffer =3D (UINT8 *)AllocatePages (RequiredPages);=0D +=0D + if (MmCommunicateBuffer =3D=3D NULL) {=0D + Status =3D EFI_OUT_OF_RESOURCES;=0D + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory: %r\n", __func__, = Status));=0D + return Status;=0D + }=0D +=0D + // Zero the entire Communication Buffer=0D + ZeroMem (MmCommunicateBuffer, (RequiredPages * EFI_PAGE_SIZE));=0D +=0D + //=0D + // Program all payload structure contents=0D + //=0D + MmVarAccessHeader =3D (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)(MmCom= municateBuffer + MM_VARIABLE_COMM_BUFFER_OFFSET);=0D +=0D + // Variable GUID=0D + CopyMem ((VOID *)&MmVarAccessHeader->Guid, VariableGuid, sizeof (GUID));= =0D +=0D + // Program the max amount of data we accept.=0D + MmVarAccessHeader->DataSize =3D *DataSize;=0D +=0D + // Get size of the variable name=0D + MmVarAccessHeader->NameSize =3D StrSize (VariableName);=0D +=0D + // Populate incoming variable name=0D + CopyMem ((VOID *)&MmVarAccessHeader->Name, VariableName, MmVarAccessHead= er->NameSize);=0D +=0D + Status =3D PopulateHeaderAndCommunicate (MmCommunicateBuffer, MessageSiz= e, SMM_VARIABLE_FUNCTION_GET_VARIABLE);=0D + if (EFI_ERROR (Status)) {=0D + // We received an error from either communicate or Variable Service.=0D + if (Status !=3D EFI_BUFFER_TOO_SMALL) {=0D + DEBUG ((DEBUG_ERROR, "%a - Communite to MM for variable service erro= red: %r\n", __func__, Status));=0D + }=0D +=0D + goto Exit;=0D + }=0D +=0D + Status =3D EFI_SUCCESS;=0D +=0D + // User provided buffer is too small=0D + if (*DataSize < MmVarAccessHeader->DataSize) {=0D + Status =3D EFI_BUFFER_TOO_SMALL;=0D + }=0D +=0D +Exit:=0D + // Check if we need to set Attributes=0D + if (Attributes !=3D NULL) {=0D + *Attributes =3D MmVarAccessHeader->Attributes;=0D + }=0D +=0D + *DataSize =3D MmVarAccessHeader->DataSize;=0D +=0D + if (Status =3D=3D EFI_SUCCESS) {=0D + CopyMem ((VOID *)Data, (UINT8 *)MmVarAccessHeader->Name + MmVarAccessH= eader->NameSize, *DataSize);=0D + }=0D +=0D + // Free the Communication Buffer=0D + if (MmCommunicateBuffer !=3D NULL) {=0D + FreePages (MmCommunicateBuffer, RequiredPages);=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Return the next variable name and GUID.=0D +=0D + This function is called multiple times to retrieve the VariableName=0D + and VariableGuid of all variables currently available in the system.=0D + On each call, the previous results are passed into the interface,=0D + and, on return, the interface returns the data for the next=0D + interface. When the entire variable list has been returned,=0D + EFI_NOT_FOUND is returned.=0D +=0D + @param This A pointer to this instance of the EFI_PEI_READ= _ONLY_VARIABLE2_PPI.=0D +=0D + @param VariableNameSize On entry, points to the size of the buffer poi= nted to by VariableName.=0D + On return, the size of the variable name buffe= r.=0D + @param VariableName On entry, a pointer to a null-terminated strin= g that is the variable's name.=0D + On return, points to the next variable's null-= terminated name string.=0D +=0D + @param VariableGuid On entry, a pointer to an EFI_GUID that is the= variable's GUID.=0D + On return, a pointer to the next variable's GU= ID.=0D +=0D + @retval EFI_SUCCESS The variable was read successfully.=0D + @retval EFI_NOT_FOUND The variable could not be found.=0D + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the = resulting=0D + data. VariableNameSize is updated with the= size=0D + required for the specified variable.=0D + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or=0D + VariableNameSize is NULL.=0D + @retval EFI_DEVICE_ERROR The variable could not be retrieved becaus= e of a device error.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiMmGetNextVariableName (=0D + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,=0D + IN OUT UINTN *VariableNameSize,=0D + IN OUT CHAR16 *VariableName,=0D + IN OUT EFI_GUID *VariableGuid=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINTN MessageSize;=0D + UINT8 *MmCommunicateBuffer;=0D + SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *MmVarGetNextVarHeader;= =0D + UINTN RequiredPages;=0D +=0D + // Check input parameters=0D + if ((VariableName =3D=3D NULL) ||=0D + (VariableGuid =3D=3D NULL) ||=0D + (VariableNameSize =3D=3D NULL) ||=0D + (*VariableNameSize =3D=3D 0))=0D + {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + // Allocate required pages to send MM request=0D + MessageSize =3D MM_VARIABLE_COMM_BUFFER_OFFSET +=0D + OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)= +=0D + StrSize (VariableName) + *VariableNameSize;=0D +=0D + RequiredPages =3D EFI_SIZE_TO_PAGES (MessageSize);=0D + MmCommunicateBuffer =3D (UINT8 *)AllocatePages (RequiredPages);=0D +=0D + if (MmCommunicateBuffer =3D=3D NULL) {=0D + Status =3D EFI_OUT_OF_RESOURCES;=0D + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory: %r\n", __func__, = Status));=0D + return Status;=0D + }=0D +=0D + // Zero the entire Communication Buffer=0D + ZeroMem (MmCommunicateBuffer, (RequiredPages * EFI_PAGE_SIZE));=0D +=0D + //=0D + // Program all payload structure contents=0D + //=0D + MmVarGetNextVarHeader =3D (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NA= ME *)(MmCommunicateBuffer + MM_VARIABLE_COMM_BUFFER_OFFSET);=0D +=0D + // Variable GUID=0D + CopyMem ((VOID *)&MmVarGetNextVarHeader->Guid, VariableGuid, sizeof (GUI= D));=0D +=0D + // Program the maximal length of name we can accept.=0D + MmVarGetNextVarHeader->NameSize =3D *VariableNameSize;=0D +=0D + // Populate incoming variable name=0D + CopyMem ((VOID *)&MmVarGetNextVarHeader->Name, VariableName, MmVarGetNex= tVarHeader->NameSize);=0D +=0D + // Send the MM request using MmCommunicationPei=0D + Status =3D PopulateHeaderAndCommunicate (MmCommunicateBuffer, MessageSiz= e, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME);=0D + if (EFI_ERROR (Status)) {=0D + // We received an error from either communicate or Variable Service.=0D + if (Status !=3D EFI_BUFFER_TOO_SMALL) {=0D + DEBUG ((DEBUG_ERROR, "%a - Communite to MM for variable service erro= red: %r\n", __func__, Status));=0D + }=0D +=0D + goto Exit;=0D + }=0D +=0D + Status =3D EFI_SUCCESS;=0D +=0D + // User provided buffer is too small=0D + if (*VariableNameSize < MmVarGetNextVarHeader->NameSize) {=0D + Status =3D EFI_BUFFER_TOO_SMALL;=0D + }=0D +=0D +Exit:=0D + // Update the name size to be returned=0D + *VariableNameSize =3D MmVarGetNextVarHeader->NameSize;=0D +=0D + if (Status =3D=3D EFI_SUCCESS) {=0D + CopyMem ((VOID *)VariableName, (UINT8 *)MmVarGetNextVarHeader->Name, *= VariableNameSize);=0D + CopyMem ((VOID *)VariableGuid, (UINT8 *)&(MmVarGetNextVarHeader->Guid)= , sizeof (EFI_GUID));=0D + }=0D +=0D + // Free the Communication Buffer=0D + if (MmCommunicateBuffer !=3D NULL) {=0D + FreePages (MmCommunicateBuffer, RequiredPages);=0D + }=0D +=0D + return Status;=0D +}=0D diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 5b1f50e9c084..1aedfe280ae1 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -400,6 +400,7 @@ [Components] MdeModulePkg/Application/VariableInfo/VariableInfo.inf=0D MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf=0D MdeModulePkg/Universal/Variable/Pei/VariablePei.inf=0D + MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf=0D MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf=0D MdeModulePkg/Universal/TimestampDxe/TimestampDxe.inf=0D MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf=0D diff --git a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h = b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h new file mode 100644 index 000000000000..0feed8cd1cb6 --- /dev/null +++ b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h @@ -0,0 +1,134 @@ +/** @file -- MmVariablePei.h=0D + Provides interface for reading Secure System Variables during PEI.=0D +=0D + Copyright (c) Microsoft Corporation.=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#ifndef PEI_MM_VARIABLE_LIB_H_=0D +#define PEI_MM_VARIABLE_LIB_H_=0D +=0D +#include =0D +#include =0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#include =0D +=0D +#include =0D +#include =0D +=0D +#include =0D +#include =0D +=0D +/**=0D + Entry point of PEI Secure Variable read driver=0D +=0D + @param FileHandle Handle of the file being invoked.=0D + Type EFI_PEI_FILE_HANDLE is defined in FfsFindNextF= ile().=0D + @param PeiServices General purpose services available to every PEIM.=0D +=0D + @retval EFI_SUCCESS If the interface could be successfully installed=0D + @retval Others Returned from PeiServicesInstallPpi()=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiMmVariableInitialize (=0D + IN EFI_PEI_FILE_HANDLE FileHandle,=0D + IN CONST EFI_PEI_SERVICES **PeiServices=0D + );=0D +=0D +/**=0D +=0D + This function enables the read of Secure Variables during PEI.=0D +=0D + This function is using the Secure Variable Store.If the Data=0D + buffer is too small to hold the contents of the variable, the error=0D + EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the required buf= fer=0D + size to obtain the data.=0D +=0D + The function performs the following:=0D +=0D + 1) Creates an MM request=0D + 2) Fills out the following data structures for the Secure Variable Servi= ce=0D + SMM_VARIABLE_COMMUNICATE_HEADER/SMM_VARIABLE_COMMUNICATE_ACCESS_VARI= ABLE=0D + 3) Adds the MM data structures to the MM request.=0D + 4) Sends the MM request to EL3 using MmCommunicationPeiLib.=0D + 5) The MM request is sent to S-EL0.=0D + 6) The MM request is then handled by the registered handler with GUID: g= EfiSmmVariableProtocolGuid=0D +=0D + @param This A pointer to this instance of the EFI_PEI_= READ_ONLY_VARIABLE2_PPI.=0D + @param VariableName A pointer to a null-terminated string that= is the variable's name.=0D + @param VariableGuid A pointer to an EFI_GUID that is the varia= ble's GUID. The combination of=0D + VariableGuid and VariableName must be uniq= ue.=0D + @param Attributes If non-NULL, on return, points to the vari= able's attributes.=0D + @param DataSize On entry, points to the size in bytes of t= he Data buffer.=0D + On return, points to the size of the data = returned in Data.=0D + @param Data Points to the buffer which will hold the r= eturned variable value.=0D + May be NULL with a zero DataSize in order = to determine the size of the buffer needed.=0D +=0D + @retval EFI_SUCCESS The variable was read successfully.=0D + @retval EFI_NOT_FOUND The variable was not found.=0D + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the resultin= g data.=0D + DataSize is updated with the size required= for=0D + the specified variable.=0D + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid, DataSize or Da= ta is NULL.=0D + @retval EFI_DEVICE_ERROR The variable could not be retrieved becaus= e of a device error.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiMmGetVariable (=0D + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,=0D + IN CONST CHAR16 *VariableName,=0D + IN CONST EFI_GUID *VariableGuid,=0D + OUT UINT32 *Attributes,=0D + IN OUT UINTN *DataSize,=0D + OUT VOID *Data OPTIONAL=0D + );=0D +=0D +/**=0D + Return the next variable name and GUID.=0D +=0D + This function is called multiple times to retrieve the VariableName=0D + and VariableGuid of all variables currently available in the system.=0D + On each call, the previous results are passed into the interface,=0D + and, on return, the interface returns the data for the next=0D + interface. When the entire variable list has been returned,=0D + EFI_NOT_FOUND is returned.=0D +=0D + @param This A pointer to this instance of the EFI_PEI_READ= _ONLY_VARIABLE2_PPI.=0D +=0D + @param VariableNameSize On entry, points to the size of the buffer poi= nted to by VariableName.=0D + On return, the size of the variable name buffe= r.=0D + @param VariableName On entry, a pointer to a null-terminated strin= g that is the variable's name.=0D + On return, points to the next variable's null-= terminated name string.=0D +=0D + @param VariableGuid On entry, a pointer to an EFI_GUID that is the= variable's GUID.=0D + On return, a pointer to the next variable's GU= ID.=0D +=0D + @retval EFI_SUCCESS The variable was read successfully.=0D + @retval EFI_NOT_FOUND The variable could not be found.=0D + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the = resulting=0D + data. VariableNameSize is updated with the= size=0D + required for the specified variable.=0D + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or=0D + VariableNameSize is NULL.=0D + @retval EFI_DEVICE_ERROR The variable could not be retrieved becaus= e of a device error.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiMmGetNextVariableName (=0D + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,=0D + IN OUT UINTN *VariableNameSize,=0D + IN OUT CHAR16 *VariableName,=0D + IN OUT EFI_GUID *VariableGuid=0D + );=0D +=0D +#endif /* PEI_MM_VARIABLE_LIB_H_ */=0D diff --git a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.in= f b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf new file mode 100644 index 000000000000..d122703e9b5d --- /dev/null +++ b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf @@ -0,0 +1,43 @@ +## @file -- MmVariablePei.inf=0D +# Provides interface for reading Secure System Variables during PEI.=0D +#=0D +# Copyright (c) Microsoft Corporation.=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +##=0D +=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D MmVariablePei=0D + FILE_GUID =3D CD660A87-454B-4346-A35C-3D89BF8ECFAF= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D PeiMmVariableInitialize=0D +=0D +[Sources]=0D + MmVariablePei.c=0D + MmVariablePei.h=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D +=0D +[LibraryClasses]=0D + PcdLib=0D + PeiServicesLib=0D + PeimEntryPoint=0D + MemoryAllocationLib=0D + HobLib=0D +=0D +[Pcd]=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize=0D +=0D +[Protocols]=0D + gEfiSmmVariableProtocolGuid ## CONSUMES=0D +=0D +[Ppis]=0D + gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES=0D + gEfiPeiMmCommunicationPpiGuid ## CONSUMES=0D +=0D +[Depex]=0D + gEfiPeiMmCommunicationPpiGuid=0D --=20 2.40.1.windows.1