MdeModulePkg/FaultTolerantWriteDxe: factor out boot service accesses
[mirror_edk2.git] / MdeModulePkg / Universal / FaultTolerantWriteDxe / FaultTolerantWriteSmmCommon.h
1 /** @file\r
2 \r
3   The common header file for SMM FTW module and SMM FTW DXE Module.\r
4 \r
5 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved. <BR>\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution.  The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15 \r
16 #ifndef __SMM_FTW_COMMON_H__\r
17 #define __SMM_FTW_COMMON_H__\r
18 \r
19 #include <Protocol/SmmFirmwareVolumeBlock.h>\r
20 #include <Protocol/SmmFaultTolerantWrite.h>\r
21 \r
22 #define FTW_FUNCTION_GET_MAX_BLOCK_SIZE       1\r
23 #define FTW_FUNCTION_ALLOCATE                 2\r
24 #define FTW_FUNCTION_WRITE                    3\r
25 #define FTW_FUNCTION_RESTART                  4\r
26 #define FTW_FUNCTION_ABORT                    5\r
27 #define FTW_FUNCTION_GET_LAST_WRITE           6\r
28 \r
29 typedef struct {\r
30   UINTN       Function;\r
31   EFI_STATUS  ReturnStatus;\r
32   UINT8       Data[1];\r
33 } SMM_FTW_COMMUNICATE_FUNCTION_HEADER;\r
34 \r
35 ///\r
36 /// Size of SMM communicate header, without including the payload.\r
37 ///\r
38 #define SMM_COMMUNICATE_HEADER_SIZE  (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data))\r
39 \r
40 ///\r
41 /// Size of SMM FTW communicate function header, without including the payload.\r
42 ///\r
43 #define SMM_FTW_COMMUNICATE_HEADER_SIZE  (OFFSET_OF (SMM_FTW_COMMUNICATE_FUNCTION_HEADER, Data))\r
44 \r
45 typedef struct {\r
46   UINTN                                 BlockSize;\r
47 } SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER;\r
48 \r
49 typedef struct {\r
50   EFI_GUID                              CallerId;\r
51   UINTN                                 PrivateDataSize;\r
52   UINTN                                 NumberOfWrites;\r
53 } SMM_FTW_ALLOCATE_HEADER;\r
54 \r
55 typedef struct {\r
56   EFI_LBA                               Lba;\r
57   UINTN                                 Offset;\r
58   UINTN                                 PrivateDataSize;\r
59   EFI_PHYSICAL_ADDRESS                  FvbBaseAddress;\r
60   EFI_FVB_ATTRIBUTES_2                  FvbAttributes;\r
61   UINTN                                 Length;\r
62   UINT8                                 Data[1];\r
63 } SMM_FTW_WRITE_HEADER;\r
64 \r
65 typedef struct {\r
66   EFI_PHYSICAL_ADDRESS                  FvbBaseAddress;\r
67   EFI_FVB_ATTRIBUTES_2                  FvbAttributes;\r
68 } SMM_FTW_RESTART_HEADER;\r
69 \r
70 typedef struct {\r
71   EFI_GUID                              CallerId;\r
72   EFI_LBA                               Lba;\r
73   UINTN                                 Offset;\r
74   UINTN                                 Length;\r
75   UINTN                                 PrivateDataSize;\r
76   BOOLEAN                               Complete;\r
77   UINT8                                 Data[1];\r
78 } SMM_FTW_GET_LAST_WRITE_HEADER;\r
79 \r
80 /**\r
81   Shared entry point of the module\r
82 \r
83   @retval EFI_SUCCESS           The initialization finished successfully.\r
84   @retval EFI_OUT_OF_RESOURCES  Allocate memory error\r
85   @retval EFI_INVALID_PARAMETER Workspace or Spare block does not exist\r
86 \r
87 **/\r
88 EFI_STATUS\r
89 MmFaultTolerantWriteInitialize (\r
90   VOID\r
91   );\r
92 \r
93 /**\r
94   This function checks if the buffer is valid per processor architecture and\r
95   does not overlap with SMRAM.\r
96 \r
97   @param Buffer The buffer start address to be checked.\r
98   @param Length The buffer length to be checked.\r
99 \r
100   @retval TRUE  This buffer is valid per processor architecture and does not\r
101                 overlap with SMRAM.\r
102   @retval FALSE This buffer is not valid per processor architecture or overlaps\r
103                 with SMRAM.\r
104 **/\r
105 BOOLEAN\r
106 FtwSmmIsBufferOutsideSmmValid (\r
107   IN EFI_PHYSICAL_ADDRESS  Buffer,\r
108   IN UINT64                Length\r
109   );\r
110 \r
111 /**\r
112   Notify the system that the SMM FTW driver is ready\r
113 **/\r
114 VOID\r
115 FtwNotifySmmReady (\r
116   VOID\r
117   );\r
118 \r
119 #endif\r