]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditionalMm.c
MdeModulePkg/FaultTolerantWriteDxe: implement standalone MM version
[mirror_edk2.git] / MdeModulePkg / Universal / FaultTolerantWriteDxe / FaultTolerantWriteTraditionalMm.c
CommitLineData
22cedf5b
AB
1/** @file\r
2\r
3 Parts of the SMM/MM implementation that are specific to traditional MM\r
4\r
5Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved. <BR>\r
6Copyright (c) 2018, Linaro, Ltd. All rights reserved. <BR>\r
7This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include <Library/SmmMemLib.h>\r
18#include <Library/UefiBootServicesTableLib.h>\r
19#include "FaultTolerantWrite.h"\r
20#include "FaultTolerantWriteSmmCommon.h"\r
21\r
22/**\r
23 This function checks if the buffer is valid per processor architecture and\r
24 does not overlap with SMRAM.\r
25\r
26 @param Buffer The buffer start address to be checked.\r
27 @param Length The buffer length to be checked.\r
28\r
29 @retval TRUE This buffer is valid per processor architecture and does not\r
30 overlap with SMRAM.\r
31 @retval FALSE This buffer is not valid per processor architecture or overlaps\r
32 with SMRAM.\r
33**/\r
34BOOLEAN\r
35FtwSmmIsBufferOutsideSmmValid (\r
36 IN EFI_PHYSICAL_ADDRESS Buffer,\r
37 IN UINT64 Length\r
38 )\r
39{\r
40 return SmmIsBufferOutsideSmmValid (Buffer, Length);\r
41}\r
42\r
43/**\r
44 Internal implementation of CRC32. Depending on the execution context\r
45 (traditional SMM or DXE vs standalone MM), this function is implemented\r
46 via a call to the CalculateCrc32 () boot service, or via a library\r
47 call.\r
48\r
49 If Buffer is NULL, then ASSERT().\r
50 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
51\r
52 @param[in] Buffer A pointer to the buffer on which the 32-bit CRC is\r
53 to be computed.\r
54 @param[in] Length The number of bytes in the buffer Data.\r
55\r
56 @retval Crc32 The 32-bit CRC was computed for the data buffer.\r
57\r
58**/\r
59UINT32\r
60FtwCalculateCrc32 (\r
61 IN VOID *Buffer,\r
62 IN UINTN Length\r
63 )\r
64{\r
65 EFI_STATUS Status;\r
66 UINT32 ReturnValue;\r
67\r
68 Status = gBS->CalculateCrc32 (Buffer, Length, &ReturnValue);\r
69 ASSERT_EFI_ERROR (Status);\r
70\r
71 return ReturnValue;\r
72}\r
73\r
74/**\r
75 Notify the system that the SMM FTW driver is ready\r
76**/\r
77VOID\r
78FtwNotifySmmReady (\r
79 VOID\r
80 )\r
81{\r
82 EFI_HANDLE FtwHandle;\r
83 EFI_STATUS Status;\r
84\r
85 FtwHandle = NULL;\r
86 Status = gBS->InstallProtocolInterface (\r
87 &FtwHandle,\r
88 &gEfiSmmFaultTolerantWriteProtocolGuid,\r
89 EFI_NATIVE_INTERFACE,\r
90 NULL\r
91 );\r
92 ASSERT_EFI_ERROR (Status);\r
93}\r
94\r
95/**\r
96 This function is the entry point of the Fault Tolerant Write driver.\r
97\r
98 @param[in] ImageHandle A handle for the image that is initializing this driver\r
99 @param[in] SystemTable A pointer to the EFI system table\r
100\r
101 @retval EFI_SUCCESS The initialization finished successfully.\r
102 @retval EFI_OUT_OF_RESOURCES Allocate memory error\r
103 @retval EFI_INVALID_PARAMETER Workspace or Spare block does not exist\r
104\r
105**/\r
106EFI_STATUS\r
107EFIAPI\r
108SmmFaultTolerantWriteInitialize (\r
109 IN EFI_HANDLE ImageHandle,\r
110 IN EFI_SYSTEM_TABLE *SystemTable\r
111 )\r
112{\r
113 return MmFaultTolerantWriteInitialize ();\r
114}\r