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