]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/BaseCryptLibOnProtocolPpi/SmmCryptLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLibOnProtocolPpi / SmmCryptLib.c
CommitLineData
cd70de1c
MK
1/** @file\r
2 Implements the GetCryptoServices() API that retuns a pointer to the EDK II\r
3 SMM Crypto Protocol.\r
4\r
5 Copyright (C) Microsoft Corporation. All rights reserved.\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7\r
8**/\r
9\r
10#include <PiSmm.h>\r
11#include <Library/BaseLib.h>\r
12#include <Library/DebugLib.h>\r
13#include <Library/SmmServicesTableLib.h>\r
14#include <Protocol/SmmCrypto.h>\r
15\r
16EDKII_SMM_CRYPTO_PROTOCOL *mSmmCryptoProtocol = NULL;\r
17\r
18/**\r
19 Internal worker function that returns the pointer to an EDK II Crypto\r
20 Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are\r
21 identical which allows the implementation of the BaseCryptLib functions that\r
22 call through a Protocol/PPI to be shared for the PEI, DXE, and SMM\r
23 implementations.\r
24\r
25 This SMM implementation returns the pointer to the EDK II SMM Crypto Protocol\r
26 that was found in the library constructor SmmCryptLibConstructor().\r
27**/\r
28VOID *\r
29GetCryptoServices (\r
30 VOID\r
31 )\r
32{\r
33 return (VOID *)mSmmCryptoProtocol;\r
34}\r
35\r
36/**\r
37 Constructor looks up the EDK II SMM Crypto Protocol and verifies that it is\r
38 not NULL and has a high enough version value to support all the BaseCryptLib\r
39 functions.\r
40\r
41 @param ImageHandle The firmware allocated handle for the EFI image.\r
42 @param SystemTable A pointer to the EFI System Table.\r
43\r
44 @retval EFI_SUCCESS The EDK II SMM Crypto Protocol was found.\r
45 @retval EFI_NOT_FOUND The EDK II SMM Crypto Protocol was not found.\r
46**/\r
47EFI_STATUS\r
48EFIAPI\r
49SmmCryptLibConstructor (\r
50 IN EFI_HANDLE ImageHandle,\r
51 IN EFI_SYSTEM_TABLE *SystemTable\r
52 )\r
53{\r
54 EFI_STATUS Status;\r
55 UINTN Version;\r
56\r
57 Status = gSmst->SmmLocateProtocol (\r
58 &gEdkiiSmmCryptoProtocolGuid,\r
59 NULL,\r
60 (VOID **)&mSmmCryptoProtocol\r
61 );\r
7c342378
MK
62 if (EFI_ERROR (Status) || (mSmmCryptoProtocol == NULL)) {\r
63 DEBUG ((DEBUG_ERROR, "[SmmCryptLib] Failed to locate Crypto SMM Protocol. Status = %r\n", Status));\r
cd70de1c
MK
64 ASSERT_EFI_ERROR (Status);\r
65 ASSERT (mSmmCryptoProtocol != NULL);\r
66 mSmmCryptoProtocol = NULL;\r
67 return EFI_NOT_FOUND;\r
68 }\r
69\r
70 Version = mSmmCryptoProtocol->GetVersion ();\r
71 if (Version < EDKII_CRYPTO_VERSION) {\r
7c342378 72 DEBUG ((DEBUG_ERROR, "[SmmCryptLib] Crypto SMM Protocol unsupported version %d\n", Version));\r
cd70de1c
MK
73 ASSERT (Version >= EDKII_CRYPTO_VERSION);\r
74 mSmmCryptoProtocol = NULL;\r
75 return EFI_NOT_FOUND;\r
76 }\r
77\r
78 return EFI_SUCCESS;\r
79}\r