From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from walk.intel-email.com (walk.intel-email.com [101.227.64.242]) by mx.groups.io with SMTP id smtpd.web10.5279.1687659790343322152 for ; Sat, 24 Jun 2023 19:23:13 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@byosoft.com.cn header.s=cloud-union header.b=d0DZdAdF; spf=pass (domain: byosoft.com.cn, ip: 101.227.64.242, mailfrom: gaoliming@byosoft.com.cn) Received: from walk.intel-email.com (localhost [127.0.0.1]) by walk.intel-email.com (Postfix) with ESMTP id C33E0CD1F664 for ; Sun, 25 Jun 2023 10:23:07 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=byosoft.com.cn; s=cloud-union; t=1687659787; bh=RoQS2UhGLhPgbLqd7dHulkl+YvZD6cTX0Gqb4HEJcMw=; h=From:To:Cc:References:In-Reply-To:Subject:Date; b=d0DZdAdF+w3EAAKl20HWWBhEMpteBQeKkrLLW8DijQKJR5jyoKCQdru9UDvMXTQwc 6bOgDRvuQySEYqucV14YmzKmMlJjYj4gisDRvQr9UowlgrlD3NQ5DrYW9GB1kp+UE6 naDgJ/qo32tcT7LLStUTzt+L0w7WjNVZgcpewcSc= Received: from localhost (localhost [127.0.0.1]) by walk.intel-email.com (Postfix) with ESMTP id BECAFCD1F65A for ; Sun, 25 Jun 2023 10:23:07 +0800 (CST) Received: from walk.intel-email.com (localhost [127.0.0.1]) by walk.intel-email.com (Postfix) with ESMTP id 8A71DCD1F64A for ; Sun, 25 Jun 2023 10:23:07 +0800 (CST) Authentication-Results: walk.intel-email.com; none Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by walk.intel-email.com (Postfix) with SMTP id 1EAEACD1F65A for ; Sun, 25 Jun 2023 10:23:04 +0800 (CST) Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Sun, 25 Jun 2023 10:23:04 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: , Cc: "'Hao A Wu'" , "'Jian J Wang'" , "'Ronny Hansen'" , "'Shriram Masanamuthu Chinnathurai'" , "'Preshit Harlikar'" References: <20230608204434.2325-1-kuqin12@gmail.com> <20230608204434.2325-3-kuqin12@gmail.com> In-Reply-To: <20230608204434.2325-3-kuqin12@gmail.com> Subject: =?UTF-8?B?5Zue5aSNOiBbZWRrMi1kZXZlbF0gW1BBVENIIHYxIDIvMl0gTWRlTW9kdWxlUGtnOiBWYXJpYWJsZTogSW50cm9kdWNlIE1NIGJhc2VkIHZhcmlhYmxlIHJlYWQgc2VydmljZSBpbiBQRUk=?= Date: Sun, 25 Jun 2023 10:23:04 +0800 Message-ID: <03c601d9a70b$f91bfc60$eb53f520$@byosoft.com.cn> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQG+g+FsfZi87AfOydUXn847m31HOwI+cahAr78cWSA= Sender: "gaoliming" Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn Kun: Seemly, PcdMaxVariableSize is not used by this module. It can be = removed.=20 And, has its functionality been verified in the real platform? Thanks Liming > -----=D3=CA=BC=FE=D4=AD=BC=FE----- > =B7=A2=BC=FE=C8=CB: devel@edk2.groups.io = =B4=FA=B1=ED Kun Qin > =B7=A2=CB=CD=CA=B1=BC=E4: 2023=C4=EA6=D4=C29=C8=D5 4:45 > =CA=D5=BC=FE=C8=CB: devel@edk2.groups.io > =B3=AD=CB=CD: Hao A Wu ; Liming Gao > ; Jian J Wang ; Ronny > Hansen ; Shriram Masanamuthu > Chinnathurai ; Preshit Harlikar > > =D6=F7=CC=E2: [edk2-devel] [PATCH v1 2/2] MdeModulePkg: Variable: = Introduce MM > based variable read service in PEI >=20 > From: Kun Qin >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4464 >=20 > This change introduced the Standalone MM based variable read = capability > in PEI phase for applicable platforms (such as ARM platforms). >=20 > Similar to the x86 counterpart, MM communicate PPI is used to request > variable information from Standalone MM environment. >=20 > Cc: Hao A Wu > Cc: Liming Gao > Cc: Jian J Wang >=20 > 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(+) >=20 > 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 >=20 > + Provides interface for reading Secure System Variables during PEI. >=20 > + >=20 > + Copyright (c) 2006 - 2019, Intel Corporation. All rights = reserved.
>=20 > + Copyright (c) Microsoft Corporation.
>=20 > + SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +**/ >=20 > + >=20 > +#include "MmVariablePei.h" >=20 > + >=20 > +#define MM_VARIABLE_COMM_BUFFER_OFFSET > (SMM_COMMUNICATE_HEADER_SIZE + > SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) >=20 > + >=20 > +// >=20 > +// Module globals >=20 > +// >=20 > +EFI_PEI_READ_ONLY_VARIABLE2_PPI mPeiSecureVariableRead =3D { >=20 > + PeiMmGetVariable, >=20 > + PeiMmGetNextVariableName >=20 > +}; >=20 > + >=20 > +EFI_PEI_PPI_DESCRIPTOR mPeiMmVariablePpi =3D { >=20 > + (EFI_PEI_PPI_DESCRIPTOR_PPI | > EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), >=20 > + &gEfiPeiReadOnlyVariable2PpiGuid, >=20 > + &mPeiSecureVariableRead >=20 > +}; >=20 > + >=20 > +/** >=20 > + Entry point of PEI Secure Variable read driver >=20 > + >=20 > + @param FileHandle Handle of the file being invoked. >=20 > + Type EFI_PEI_FILE_HANDLE is defined in > FfsFindNextFile(). >=20 > + @param PeiServices General purpose services available to every > PEIM. >=20 > + >=20 > + @retval EFI_SUCCESS If the interface could be successfully = installed >=20 > + @retval Others Returned from PeiServicesInstallPpi() >=20 > +**/ >=20 > +EFI_STATUS >=20 > +EFIAPI >=20 > +PeiMmVariableInitialize ( >=20 > + IN EFI_PEI_FILE_HANDLE FileHandle, >=20 > + IN CONST EFI_PEI_SERVICES **PeiServices >=20 > + ) >=20 > +{ >=20 > + return PeiServicesInstallPpi (&mPeiMmVariablePpi); >=20 > +} >=20 > + >=20 > +/** >=20 > + Helper function to populate MM communicate header and variable > communicate header >=20 > + and then communicate to PEI. >=20 > + >=20 > + @param[in, out] CommunicateBuffer Size of the variable name. >=20 > + @param[in] CommunicateBufferSize The entire buffer size to = be > sent to MM. >=20 > + @param[in] Function The MM variable function > value. >=20 > + >=20 > + @retval EFI_INVALID_PARAMETER Invalid parameter. >=20 > + @retval EFI_SUCCESS Find the specified variable. >=20 > + @retval Others Errors returned by MM > communicate or variable service. >=20 > + >=20 > +**/ >=20 > +EFI_STATUS >=20 > +PopulateHeaderAndCommunicate ( >=20 > + IN OUT UINT8 *CommunicateBuffer, >=20 > + IN UINTN CommunicateBufferSize, >=20 > + IN UINTN Function >=20 > + ) >=20 > +{ >=20 > + EFI_STATUS Status; >=20 > + EFI_PEI_MM_COMMUNICATION_PPI *MmCommunicationPpi; >=20 > + EFI_MM_COMMUNICATE_HEADER *MmCommunicateHeader; >=20 > + SMM_VARIABLE_COMMUNICATE_HEADER *MmVarCommsHeader; >=20 > + >=20 > + // Minimal sanity check >=20 > + if ((CommunicateBuffer =3D=3D NULL) || >=20 > + (CommunicateBufferSize < > MM_VARIABLE_COMM_BUFFER_OFFSET)) >=20 > + { >=20 > + Status =3D EFI_INVALID_PARAMETER; >=20 > + DEBUG ((DEBUG_ERROR, "%a: Invalid incoming parameters: %p and > 0x%x\n", __func__, CommunicateBuffer, CommunicateBufferSize)); >=20 > + goto Exit; >=20 > + } >=20 > + >=20 > + if ((Function !=3D > SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME) && >=20 > + (Function !=3D SMM_VARIABLE_FUNCTION_GET_VARIABLE)) >=20 > + { >=20 > + Status =3D EFI_INVALID_PARAMETER; >=20 > + DEBUG ((DEBUG_ERROR, "%a: Invalid function value: 0x%x\n", > __func__, Function)); >=20 > + goto Exit; >=20 > + } >=20 > + >=20 > + Status =3D PeiServicesLocatePpi (&gEfiPeiMmCommunicationPpiGuid, 0, > NULL, (VOID **)&MmCommunicationPpi); >=20 > + if (EFI_ERROR (Status)) { >=20 > + DEBUG ((DEBUG_ERROR, "%a: Failed to locate PEI MM Communication > PPI: %r\n", __func__, Status)); >=20 > + goto Exit; >=20 > + } >=20 > + >=20 > + // Zero the entire Communication Buffer Header >=20 > + MmCommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER > *)CommunicateBuffer; >=20 > + >=20 > + ZeroMem (MmCommunicateHeader, > SMM_COMMUNICATE_HEADER_SIZE); >=20 > + >=20 > + // Use gEfiSmmVariableProtocolGuid to request the MM variable = service > in Standalone MM >=20 > + CopyMem ((VOID *)&MmCommunicateHeader->HeaderGuid, > &gEfiSmmVariableProtocolGuid, sizeof (GUID)); >=20 > + >=20 > + // Program the MM header size >=20 > + MmCommunicateHeader->MessageLength =3D CommunicateBufferSize - > SMM_COMMUNICATE_HEADER_SIZE; >=20 > + >=20 > + MmVarCommsHeader =3D (SMM_VARIABLE_COMMUNICATE_HEADER > *)(CommunicateBuffer + SMM_COMMUNICATE_HEADER_SIZE); >=20 > + >=20 > + // We are only supporting GetVariable and GetNextVariableName >=20 > + MmVarCommsHeader->Function =3D Function; >=20 > + >=20 > + // Send the MM request using MmCommunicationPei >=20 > + Status =3D MmCommunicationPpi->Communicate (MmCommunicationPpi, > CommunicateBuffer, &CommunicateBufferSize); >=20 > + if (EFI_ERROR (Status)) { >=20 > + // Received an error from MM interface. >=20 > + DEBUG ((DEBUG_ERROR, "%a - MM Interface Error: %r\n", __func__, > Status)); >=20 > + goto Exit; >=20 > + } >=20 > + >=20 > + // MM request was successfully handled by the framework. >=20 > + // Set status to the Variable Service Status Code >=20 > + Status =3D MmVarCommsHeader->ReturnStatus; >=20 > + if (EFI_ERROR (Status)) { >=20 > + // We received an error from Variable Service. >=20 > + // We cant do anymore so return Status >=20 > + if (Status !=3D EFI_BUFFER_TOO_SMALL) { >=20 > + DEBUG ((DEBUG_ERROR, "%a - Variable Service Error: %r\n", > __func__, Status)); >=20 > + } >=20 > + >=20 > + goto Exit; >=20 > + } >=20 > + >=20 > +Exit: >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + This service retrieves a variable's value using its name and GUID. >=20 > + >=20 > + This function is using the Secure Variable Store. If the Data >=20 > + buffer is too small to hold the contents of the variable, the error >=20 > + EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the = required > buffer >=20 > + size to obtain the data. >=20 > + >=20 > + @param This A pointer to this instance of the > EFI_PEI_READ_ONLY_VARIABLE2_PPI. >=20 > + @param VariableName A pointer to a null-terminated string > that is the variable's name. >=20 > + @param VariableGuid A pointer to an EFI_GUID that is the > variable's GUID. The combination of >=20 > + VariableGuid and VariableName > must be unique. >=20 > + @param Attributes If non-NULL, on return, points to the > variable's attributes. >=20 > + @param DataSize On entry, points to the size in bytes > of the Data buffer. >=20 > + On return, points to the size of the > data returned in Data. >=20 > + @param Data Points to the buffer which will hold > the returned variable value. >=20 > + May be NULL with a zero DataSize in > order to determine the size of the buffer needed. >=20 > + >=20 > + @retval EFI_SUCCESS The variable was read successfully. >=20 > + @retval EFI_NOT_FOUND The variable was not found. >=20 > + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the > resulting data. >=20 > + DataSize is updated with the size > required for >=20 > + the specified variable. >=20 > + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid, DataSize > or Data is NULL. >=20 > + @retval EFI_DEVICE_ERROR The variable could not be retrieved > because of a device error. >=20 > + >=20 > +**/ >=20 > +EFI_STATUS >=20 > +EFIAPI >=20 > +PeiMmGetVariable ( >=20 > + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, >=20 > + IN CONST CHAR16 *VariableName, >=20 > + IN CONST EFI_GUID *VariableGuid, >=20 > + OUT UINT32 *Attributes, OPTIONAL >=20 > + IN OUT UINTN *DataSize, >=20 > + OUT VOID *Data OPTIONAL >=20 > + ) >=20 > +{ >=20 > + EFI_STATUS Status; >=20 > + UINTN MessageSize; >=20 > + SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE > *MmVarAccessHeader; >=20 > + UINT8 > *MmCommunicateBuffer; >=20 > + UINTN RequiredPages; >=20 > + >=20 > + // Check input parameters >=20 > + if ((VariableName =3D=3D NULL) || (VariableGuid =3D=3D NULL) || = (DataSize =3D=3D > NULL)) { >=20 > + return EFI_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + if (VariableName[0] =3D=3D 0) { >=20 > + return EFI_NOT_FOUND; >=20 > + } >=20 > + >=20 > + if ((*DataSize > 0) && (Data =3D=3D NULL)) { >=20 > + return EFI_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + // Allocate required pages to send MM request >=20 > + MessageSize =3D MM_VARIABLE_COMM_BUFFER_OFFSET + >=20 > + OFFSET_OF > (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + >=20 > + StrSize (VariableName) + *DataSize; >=20 > + >=20 > + RequiredPages =3D EFI_SIZE_TO_PAGES (MessageSize); >=20 > + MmCommunicateBuffer =3D (UINT8 *)AllocatePages (RequiredPages); >=20 > + >=20 > + if (MmCommunicateBuffer =3D=3D NULL) { >=20 > + Status =3D EFI_OUT_OF_RESOURCES; >=20 > + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory: %r\n", > __func__, Status)); >=20 > + return Status; >=20 > + } >=20 > + >=20 > + // Zero the entire Communication Buffer >=20 > + ZeroMem (MmCommunicateBuffer, (RequiredPages * EFI_PAGE_SIZE)); >=20 > + >=20 > + // >=20 > + // Program all payload structure contents >=20 > + // >=20 > + MmVarAccessHeader =3D > (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE > *)(MmCommunicateBuffer + MM_VARIABLE_COMM_BUFFER_OFFSET); >=20 > + >=20 > + // Variable GUID >=20 > + CopyMem ((VOID *)&MmVarAccessHeader->Guid, VariableGuid, sizeof > (GUID)); >=20 > + >=20 > + // Program the max amount of data we accept. >=20 > + MmVarAccessHeader->DataSize =3D *DataSize; >=20 > + >=20 > + // Get size of the variable name >=20 > + MmVarAccessHeader->NameSize =3D StrSize (VariableName); >=20 > + >=20 > + // Populate incoming variable name >=20 > + CopyMem ((VOID *)&MmVarAccessHeader->Name, VariableName, > MmVarAccessHeader->NameSize); >=20 > + >=20 > + Status =3D PopulateHeaderAndCommunicate (MmCommunicateBuffer, > MessageSize, SMM_VARIABLE_FUNCTION_GET_VARIABLE); >=20 > + if (EFI_ERROR (Status)) { >=20 > + // We received an error from either communicate or Variable = Service. >=20 > + if (Status !=3D EFI_BUFFER_TOO_SMALL) { >=20 > + DEBUG ((DEBUG_ERROR, "%a - Communite to MM for variable > service errored: %r\n", __func__, Status)); >=20 > + } >=20 > + >=20 > + goto Exit; >=20 > + } >=20 > + >=20 > + Status =3D EFI_SUCCESS; >=20 > + >=20 > + // User provided buffer is too small >=20 > + if (*DataSize < MmVarAccessHeader->DataSize) { >=20 > + Status =3D EFI_BUFFER_TOO_SMALL; >=20 > + } >=20 > + >=20 > +Exit: >=20 > + // Check if we need to set Attributes >=20 > + if (Attributes !=3D NULL) { >=20 > + *Attributes =3D MmVarAccessHeader->Attributes; >=20 > + } >=20 > + >=20 > + *DataSize =3D MmVarAccessHeader->DataSize; >=20 > + >=20 > + if (Status =3D=3D EFI_SUCCESS) { >=20 > + CopyMem ((VOID *)Data, (UINT8 *)MmVarAccessHeader->Name + > MmVarAccessHeader->NameSize, *DataSize); >=20 > + } >=20 > + >=20 > + // Free the Communication Buffer >=20 > + if (MmCommunicateBuffer !=3D NULL) { >=20 > + FreePages (MmCommunicateBuffer, RequiredPages); >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + Return the next variable name and GUID. >=20 > + >=20 > + This function is called multiple times to retrieve the VariableName >=20 > + and VariableGuid of all variables currently available in the = system. >=20 > + On each call, the previous results are passed into the interface, >=20 > + and, on return, the interface returns the data for the next >=20 > + interface. When the entire variable list has been returned, >=20 > + EFI_NOT_FOUND is returned. >=20 > + >=20 > + @param This A pointer to this instance of the > EFI_PEI_READ_ONLY_VARIABLE2_PPI. >=20 > + >=20 > + @param VariableNameSize On entry, points to the size of the = buffer > pointed to by VariableName. >=20 > + On return, the size of the variable name > buffer. >=20 > + @param VariableName On entry, a pointer to a null-terminated > string that is the variable's name. >=20 > + On return, points to the next variable's > null-terminated name string. >=20 > + >=20 > + @param VariableGuid On entry, a pointer to an EFI_GUID that = is > the variable's GUID. >=20 > + On return, a pointer to the next = variable's > GUID. >=20 > + >=20 > + @retval EFI_SUCCESS The variable was read successfully. >=20 > + @retval EFI_NOT_FOUND The variable could not be found. >=20 > + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small > for the resulting >=20 > + data. VariableNameSize is updated > with the size >=20 > + required for the specified variable. >=20 > + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or >=20 > + VariableNameSize is NULL. >=20 > + @retval EFI_DEVICE_ERROR The variable could not be retrieved > because of a device error. >=20 > +**/ >=20 > +EFI_STATUS >=20 > +EFIAPI >=20 > +PeiMmGetNextVariableName ( >=20 > + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, >=20 > + IN OUT UINTN *VariableNameSize, >=20 > + IN OUT CHAR16 *VariableName, >=20 > + IN OUT EFI_GUID *VariableGuid >=20 > + ) >=20 > +{ >=20 > + EFI_STATUS Status; >=20 > + UINTN > MessageSize; >=20 > + UINT8 > *MmCommunicateBuffer; >=20 > + SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME > *MmVarGetNextVarHeader; >=20 > + UINTN > RequiredPages; >=20 > + >=20 > + // Check input parameters >=20 > + if ((VariableName =3D=3D NULL) || >=20 > + (VariableGuid =3D=3D NULL) || >=20 > + (VariableNameSize =3D=3D NULL) || >=20 > + (*VariableNameSize =3D=3D 0)) >=20 > + { >=20 > + return EFI_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + // Allocate required pages to send MM request >=20 > + MessageSize =3D MM_VARIABLE_COMM_BUFFER_OFFSET + >=20 > + OFFSET_OF > (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + >=20 > + StrSize (VariableName) + *VariableNameSize; >=20 > + >=20 > + RequiredPages =3D EFI_SIZE_TO_PAGES (MessageSize); >=20 > + MmCommunicateBuffer =3D (UINT8 *)AllocatePages (RequiredPages); >=20 > + >=20 > + if (MmCommunicateBuffer =3D=3D NULL) { >=20 > + Status =3D EFI_OUT_OF_RESOURCES; >=20 > + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory: %r\n", > __func__, Status)); >=20 > + return Status; >=20 > + } >=20 > + >=20 > + // Zero the entire Communication Buffer >=20 > + ZeroMem (MmCommunicateBuffer, (RequiredPages * EFI_PAGE_SIZE)); >=20 > + >=20 > + // >=20 > + // Program all payload structure contents >=20 > + // >=20 > + MmVarGetNextVarHeader =3D > (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME > *)(MmCommunicateBuffer + MM_VARIABLE_COMM_BUFFER_OFFSET); >=20 > + >=20 > + // Variable GUID >=20 > + CopyMem ((VOID *)&MmVarGetNextVarHeader->Guid, VariableGuid, > sizeof (GUID)); >=20 > + >=20 > + // Program the maximal length of name we can accept. >=20 > + MmVarGetNextVarHeader->NameSize =3D *VariableNameSize; >=20 > + >=20 > + // Populate incoming variable name >=20 > + CopyMem ((VOID *)&MmVarGetNextVarHeader->Name, VariableName, > MmVarGetNextVarHeader->NameSize); >=20 > + >=20 > + // Send the MM request using MmCommunicationPei >=20 > + Status =3D PopulateHeaderAndCommunicate (MmCommunicateBuffer, > MessageSize, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME); >=20 > + if (EFI_ERROR (Status)) { >=20 > + // We received an error from either communicate or Variable = Service. >=20 > + if (Status !=3D EFI_BUFFER_TOO_SMALL) { >=20 > + DEBUG ((DEBUG_ERROR, "%a - Communite to MM for variable > service errored: %r\n", __func__, Status)); >=20 > + } >=20 > + >=20 > + goto Exit; >=20 > + } >=20 > + >=20 > + Status =3D EFI_SUCCESS; >=20 > + >=20 > + // User provided buffer is too small >=20 > + if (*VariableNameSize < MmVarGetNextVarHeader->NameSize) { >=20 > + Status =3D EFI_BUFFER_TOO_SMALL; >=20 > + } >=20 > + >=20 > +Exit: >=20 > + // Update the name size to be returned >=20 > + *VariableNameSize =3D MmVarGetNextVarHeader->NameSize; >=20 > + >=20 > + if (Status =3D=3D EFI_SUCCESS) { >=20 > + CopyMem ((VOID *)VariableName, (UINT8 > *)MmVarGetNextVarHeader->Name, *VariableNameSize); >=20 > + CopyMem ((VOID *)VariableGuid, (UINT8 > *)&(MmVarGetNextVarHeader->Guid), sizeof (EFI_GUID)); >=20 > + } >=20 > + >=20 > + // Free the Communication Buffer >=20 > + if (MmCommunicateBuffer !=3D NULL) { >=20 > + FreePages (MmCommunicateBuffer, RequiredPages); >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > 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 >=20 >=20 > MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf >=20 > MdeModulePkg/Universal/Variable/Pei/VariablePei.inf >=20 > + MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf >=20 > MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf >=20 > MdeModulePkg/Universal/TimestampDxe/TimestampDxe.inf >=20 >=20 > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf >=20 > 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 >=20 > + Provides interface for reading Secure System Variables during PEI. >=20 > + >=20 > + Copyright (c) Microsoft Corporation. >=20 > + SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +**/ >=20 > + >=20 > +#ifndef PEI_MM_VARIABLE_LIB_H_ >=20 > +#define PEI_MM_VARIABLE_LIB_H_ >=20 > + >=20 > +#include >=20 > +#include >=20 > + >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > + >=20 > +#include >=20 > + >=20 > +#include >=20 > +#include >=20 > + >=20 > +#include >=20 > +#include >=20 > + >=20 > +/** >=20 > + Entry point of PEI Secure Variable read driver >=20 > + >=20 > + @param FileHandle Handle of the file being invoked. >=20 > + Type EFI_PEI_FILE_HANDLE is defined in > FfsFindNextFile(). >=20 > + @param PeiServices General purpose services available to every > PEIM. >=20 > + >=20 > + @retval EFI_SUCCESS If the interface could be successfully = installed >=20 > + @retval Others Returned from PeiServicesInstallPpi() >=20 > +**/ >=20 > +EFI_STATUS >=20 > +EFIAPI >=20 > +PeiMmVariableInitialize ( >=20 > + IN EFI_PEI_FILE_HANDLE FileHandle, >=20 > + IN CONST EFI_PEI_SERVICES **PeiServices >=20 > + ); >=20 > + >=20 > +/** >=20 > + >=20 > + This function enables the read of Secure Variables during PEI. >=20 > + >=20 > + This function is using the Secure Variable Store.If the Data >=20 > + buffer is too small to hold the contents of the variable, the error >=20 > + EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the = required > buffer >=20 > + size to obtain the data. >=20 > + >=20 > + The function performs the following: >=20 > + >=20 > + 1) Creates an MM request >=20 > + 2) Fills out the following data structures for the Secure Variable Service >=20 > + > SMM_VARIABLE_COMMUNICATE_HEADER/SMM_VARIABLE_COMMUNICAT > E_ACCESS_VARIABLE >=20 > + 3) Adds the MM data structures to the MM request. >=20 > + 4) Sends the MM request to EL3 using MmCommunicationPeiLib. >=20 > + 5) The MM request is sent to S-EL0. >=20 > + 6) The MM request is then handled by the registered handler with = GUID: > gEfiSmmVariableProtocolGuid >=20 > + >=20 > + @param This A pointer to this instance of the > EFI_PEI_READ_ONLY_VARIABLE2_PPI. >=20 > + @param VariableName A pointer to a null-terminated string > that is the variable's name. >=20 > + @param VariableGuid A pointer to an EFI_GUID that is the > variable's GUID. The combination of >=20 > + VariableGuid and VariableName > must be unique. >=20 > + @param Attributes If non-NULL, on return, points to the > variable's attributes. >=20 > + @param DataSize On entry, points to the size in bytes > of the Data buffer. >=20 > + On return, points to the size of the > data returned in Data. >=20 > + @param Data Points to the buffer which will hold > the returned variable value. >=20 > + May be NULL with a zero DataSize in > order to determine the size of the buffer needed. >=20 > + >=20 > + @retval EFI_SUCCESS The variable was read successfully. >=20 > + @retval EFI_NOT_FOUND The variable was not found. >=20 > + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the > resulting data. >=20 > + DataSize is updated with the size > required for >=20 > + the specified variable. >=20 > + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid, DataSize > or Data is NULL. >=20 > + @retval EFI_DEVICE_ERROR The variable could not be retrieved > because of a device error. >=20 > + >=20 > +**/ >=20 > +EFI_STATUS >=20 > +EFIAPI >=20 > +PeiMmGetVariable ( >=20 > + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, >=20 > + IN CONST CHAR16 *VariableName, >=20 > + IN CONST EFI_GUID *VariableGuid, >=20 > + OUT UINT32 *Attributes, >=20 > + IN OUT UINTN *DataSize, >=20 > + OUT VOID *Data OPTIONAL >=20 > + ); >=20 > + >=20 > +/** >=20 > + Return the next variable name and GUID. >=20 > + >=20 > + This function is called multiple times to retrieve the VariableName >=20 > + and VariableGuid of all variables currently available in the = system. >=20 > + On each call, the previous results are passed into the interface, >=20 > + and, on return, the interface returns the data for the next >=20 > + interface. When the entire variable list has been returned, >=20 > + EFI_NOT_FOUND is returned. >=20 > + >=20 > + @param This A pointer to this instance of the > EFI_PEI_READ_ONLY_VARIABLE2_PPI. >=20 > + >=20 > + @param VariableNameSize On entry, points to the size of the = buffer > pointed to by VariableName. >=20 > + On return, the size of the variable name > buffer. >=20 > + @param VariableName On entry, a pointer to a null-terminated > string that is the variable's name. >=20 > + On return, points to the next variable's > null-terminated name string. >=20 > + >=20 > + @param VariableGuid On entry, a pointer to an EFI_GUID that = is > the variable's GUID. >=20 > + On return, a pointer to the next = variable's > GUID. >=20 > + >=20 > + @retval EFI_SUCCESS The variable was read successfully. >=20 > + @retval EFI_NOT_FOUND The variable could not be found. >=20 > + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small > for the resulting >=20 > + data. VariableNameSize is updated > with the size >=20 > + required for the specified variable. >=20 > + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or >=20 > + VariableNameSize is NULL. >=20 > + @retval EFI_DEVICE_ERROR The variable could not be retrieved > because of a device error. >=20 > +**/ >=20 > +EFI_STATUS >=20 > +EFIAPI >=20 > +PeiMmGetNextVariableName ( >=20 > + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, >=20 > + IN OUT UINTN *VariableNameSize, >=20 > + IN OUT CHAR16 *VariableName, >=20 > + IN OUT EFI_GUID *VariableGuid >=20 > + ); >=20 > + >=20 > +#endif /* PEI_MM_VARIABLE_LIB_H_ */ >=20 > diff --git > a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf > 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 >=20 > +# Provides interface for reading Secure System Variables during PEI. >=20 > +# >=20 > +# Copyright (c) Microsoft Corporation. >=20 > +# SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +## >=20 > + >=20 > + >=20 > +[Defines] >=20 > + INF_VERSION =3D 0x00010005 >=20 > + BASE_NAME =3D MmVariablePei >=20 > + FILE_GUID =3D > CD660A87-454B-4346-A35C-3D89BF8ECFAF >=20 > + MODULE_TYPE =3D PEIM >=20 > + VERSION_STRING =3D 1.0 >=20 > + ENTRY_POINT =3D PeiMmVariableInitialize >=20 > + >=20 > +[Sources] >=20 > + MmVariablePei.c >=20 > + MmVariablePei.h >=20 > + >=20 > +[Packages] >=20 > + MdePkg/MdePkg.dec >=20 > + MdeModulePkg/MdeModulePkg.dec >=20 > + >=20 > +[LibraryClasses] >=20 > + PcdLib >=20 > + PeiServicesLib >=20 > + PeimEntryPoint >=20 > + MemoryAllocationLib >=20 > + HobLib >=20 > + >=20 > +[Pcd] >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize >=20 > + >=20 > +[Protocols] >=20 > + gEfiSmmVariableProtocolGuid ## CONSUMES >=20 > + >=20 > +[Ppis] >=20 > + gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES >=20 > + gEfiPeiMmCommunicationPpiGuid ## CONSUMES >=20 > + >=20 > +[Depex] >=20 > + gEfiPeiMmCommunicationPpiGuid >=20 > -- > 2.40.1.windows.1 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#105956): > https://edk2.groups.io/g/devel/message/105956 > Mute This Topic: https://groups.io/mt/99415826/4905953 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub > [gaoliming@byosoft.com.cn] > -=3D-=3D-=3D-=3D-=3D-=3D >=20