]>
Commit | Line | Data |
---|---|---|
a6d73269 | 1 | /** @file\r |
b0bacc00 KM |
2 | UEFI variable support functions for Firmware Management Protocol based\r |
3 | firmware updates.\r | |
4 | \r | |
5 | Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>\r | |
67c1e5ee | 6 | Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>\r |
b0bacc00 | 7 | \r |
bcef758c | 8 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
b0bacc00 KM |
9 | \r |
10 | **/\r | |
11 | \r | |
12 | #ifndef __VARIABLE_SUPPORT_H__\r | |
13 | #define __VARIABLE_SUPPORT_H__\r | |
14 | \r | |
67c1e5ee EJ |
15 | ///\r |
16 | /// Default values for FMP Controller State information\r | |
17 | ///\r | |
b0bacc00 KM |
18 | #define DEFAULT_VERSION 0x1\r |
19 | #define DEFAULT_LOWESTSUPPORTEDVERSION 0x0\r | |
67c1e5ee EJ |
20 | #define DEFAULT_LASTATTEMPTSTATUS 0x0\r |
21 | #define DEFAULT_LASTATTEMPTVERSION 0x0\r | |
b0bacc00 | 22 | \r |
67c1e5ee EJ |
23 | ///\r |
24 | /// Base UEFI Variable names for FMP Controller State information stored in\r | |
25 | /// separate variables.\r | |
26 | ///\r | |
b0bacc00 KM |
27 | #define VARNAME_VERSION L"FmpVersion"\r |
28 | #define VARNAME_LSV L"FmpLsv"\r | |
b0bacc00 KM |
29 | #define VARNAME_LASTATTEMPTSTATUS L"LastAttemptStatus"\r |
30 | #define VARNAME_LASTATTEMPTVERSION L"LastAttemptVersion"\r | |
31 | \r | |
67c1e5ee EJ |
32 | ///\r |
33 | /// Base UEFI Variable name for FMP Controller State information stored in a\r | |
34 | /// merged UEFI Variable. If the separate UEFI Variables above are detected,\r | |
35 | /// then they are merged into a single variable and the separate variables are\r | |
36 | /// deleted.\r | |
37 | ///\r | |
38 | #define VARNAME_FMPSTATE L"FmpState"\r | |
39 | \r | |
40 | ///\r | |
41 | /// FMP Controller State structure that is used to store the state of\r | |
42 | /// a controller in one combined UEFI Variable.\r | |
43 | ///\r | |
44 | typedef struct {\r | |
45 | BOOLEAN VersionValid;\r | |
46 | BOOLEAN LsvValid;\r | |
47 | BOOLEAN LastAttemptStatusValid;\r | |
48 | BOOLEAN LastAttemptVersionValid;\r | |
49 | UINT32 Version;\r | |
50 | UINT32 Lsv;\r | |
51 | UINT32 LastAttemptStatus;\r | |
52 | UINT32 LastAttemptVersion;\r | |
53 | } FMP_CONTROLLER_STATE;\r | |
54 | \r | |
55 | /**\r | |
56 | Generate the names of the UEFI Variables used to store state information for\r | |
57 | a managed controller. The UEFI Variables names are a combination of a base\r | |
58 | name and an optional hardware instance value as a 16 character hex value. If\r | |
59 | the hardware instance value is 0, then the 16 character hex value is not\r | |
60 | included. These storage for the UEFI Variable names are allocated using the\r | |
61 | UEFI Boot Service AllocatePool() and the pointers are stored in the Private.\r | |
62 | The following are examples of variable names produces for hardware instance\r | |
63 | value 0 and value 0x1234567812345678.\r | |
64 | \r | |
65 | FmpVersion\r | |
66 | FmpLsv\r | |
67 | LastAttemptStatus\r | |
68 | LastAttemptVersion\r | |
69 | FmpDxe\r | |
70 | \r | |
71 | FmpVersion1234567812345678\r | |
72 | FmpLsv1234567812345678\r | |
73 | LastAttemptStatus1234567812345678\r | |
74 | LastAttemptVersion1234567812345678\r | |
75 | FmpDxe1234567812345678\r | |
76 | \r | |
77 | @param[in,out] Private Private context structure for the managed controller.\r | |
78 | **/\r | |
79 | VOID\r | |
80 | GenerateFmpVariableNames (\r | |
81 | IN OUT FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private\r | |
82 | );\r | |
83 | \r | |
b0bacc00 KM |
84 | /**\r |
85 | Returns the value used to fill in the Version field of the\r | |
86 | EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()\r | |
87 | service of the Firmware Management Protocol. The value is read from a UEFI\r | |
88 | variable. If the UEFI variables does not exist, then a default version value\r | |
89 | is returned.\r | |
90 | \r | |
67c1e5ee | 91 | UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"\r |
b0bacc00 | 92 | \r |
67c1e5ee | 93 | @param[in] Private Private context structure for the managed controller.\r |
b0bacc00 | 94 | \r |
67c1e5ee | 95 | @return The version of the firmware image in the firmware device.\r |
b0bacc00 KM |
96 | **/\r |
97 | UINT32\r | |
98 | GetVersionFromVariable (\r | |
67c1e5ee | 99 | IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private\r |
b0bacc00 KM |
100 | );\r |
101 | \r | |
102 | /**\r | |
103 | Returns the value used to fill in the LowestSupportedVersion field of the\r | |
104 | EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()\r | |
105 | service of the Firmware Management Protocol. The value is read from a UEFI\r | |
106 | variable. If the UEFI variables does not exist, then a default lowest\r | |
107 | supported version value is returned.\r | |
108 | \r | |
67c1e5ee EJ |
109 | UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"\r |
110 | \r | |
111 | @param[in] Private Private context structure for the managed controller.\r | |
b0bacc00 KM |
112 | \r |
113 | @return The lowest supported version of the firmware image in the firmware\r | |
114 | device.\r | |
b0bacc00 KM |
115 | **/\r |
116 | UINT32\r | |
117 | GetLowestSupportedVersionFromVariable (\r | |
67c1e5ee | 118 | IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private\r |
b0bacc00 KM |
119 | );\r |
120 | \r | |
121 | /**\r | |
122 | Returns the value used to fill in the LastAttemptStatus field of the\r | |
123 | EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()\r | |
124 | service of the Firmware Management Protocol. The value is read from a UEFI\r | |
125 | variable. If the UEFI variables does not exist, then a default last attempt\r | |
126 | status value is returned.\r | |
127 | \r | |
67c1e5ee | 128 | UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"\r |
b0bacc00 | 129 | \r |
67c1e5ee | 130 | @param[in] Private Private context structure for the managed controller.\r |
b0bacc00 | 131 | \r |
67c1e5ee | 132 | @return The last attempt status value for the most recent capsule update.\r |
b0bacc00 KM |
133 | **/\r |
134 | UINT32\r | |
135 | GetLastAttemptStatusFromVariable (\r | |
67c1e5ee | 136 | IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private\r |
b0bacc00 KM |
137 | );\r |
138 | \r | |
139 | /**\r | |
140 | Returns the value used to fill in the LastAttemptVersion field of the\r | |
141 | EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()\r | |
142 | service of the Firmware Management Protocol. The value is read from a UEFI\r | |
143 | variable. If the UEFI variables does not exist, then a default last attempt\r | |
144 | version value is returned.\r | |
145 | \r | |
67c1e5ee | 146 | UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"\r |
b0bacc00 | 147 | \r |
67c1e5ee | 148 | @param[in] Private Private context structure for the managed controller.\r |
b0bacc00 | 149 | \r |
67c1e5ee | 150 | @return The last attempt version value for the most recent capsule update.\r |
b0bacc00 KM |
151 | **/\r |
152 | UINT32\r | |
153 | GetLastAttemptVersionFromVariable (\r | |
67c1e5ee | 154 | IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private\r |
b0bacc00 KM |
155 | );\r |
156 | \r | |
157 | /**\r | |
158 | Saves the version current of the firmware image in the firmware device to a\r | |
159 | UEFI variable.\r | |
160 | \r | |
67c1e5ee | 161 | UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"\r |
b0bacc00 | 162 | \r |
67c1e5ee | 163 | @param[in] Private Private context structure for the managed controller.\r |
b0bacc00 | 164 | @param[in] Version The version of the firmware image in the firmware device.\r |
b0bacc00 KM |
165 | **/\r |
166 | VOID\r | |
167 | SetVersionInVariable (\r | |
67c1e5ee EJ |
168 | IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private,\r |
169 | IN UINT32 Version\r | |
b0bacc00 KM |
170 | );\r |
171 | \r | |
172 | /**\r | |
173 | Saves the lowest supported version current of the firmware image in the\r | |
174 | firmware device to a UEFI variable.\r | |
175 | \r | |
67c1e5ee | 176 | UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"\r |
b0bacc00 | 177 | \r |
67c1e5ee EJ |
178 | @param[in] Private Private context structure for the managed\r |
179 | controller.\r | |
180 | @param[in] LowestSupportedVersion The lowest supported version of the\r | |
181 | firmware image in the firmware device.\r | |
b0bacc00 KM |
182 | **/\r |
183 | VOID\r | |
184 | SetLowestSupportedVersionInVariable (\r | |
67c1e5ee EJ |
185 | IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private,\r |
186 | IN UINT32 LowestSupportedVersion\r | |
b0bacc00 KM |
187 | );\r |
188 | \r | |
189 | /**\r | |
190 | Saves the last attempt status value of the most recent FMP capsule update to a\r | |
191 | UEFI variable.\r | |
192 | \r | |
67c1e5ee | 193 | UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"\r |
b0bacc00 | 194 | \r |
67c1e5ee EJ |
195 | @param[in] Private Private context structure for the managed\r |
196 | controller.\r | |
b0bacc00 KM |
197 | @param[in] LastAttemptStatus The last attempt status of the most recent FMP\r |
198 | capsule update.\r | |
b0bacc00 KM |
199 | **/\r |
200 | VOID\r | |
201 | SetLastAttemptStatusInVariable (\r | |
67c1e5ee EJ |
202 | IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private,\r |
203 | IN UINT32 LastAttemptStatus\r | |
b0bacc00 KM |
204 | );\r |
205 | \r | |
206 | /**\r | |
207 | Saves the last attempt version value of the most recent FMP capsule update to\r | |
208 | a UEFI variable.\r | |
209 | \r | |
67c1e5ee | 210 | UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"\r |
b0bacc00 | 211 | \r |
67c1e5ee EJ |
212 | @param[in] Private Private context structure for the managed\r |
213 | controller.\r | |
b0bacc00 KM |
214 | @param[in] LastAttemptVersion The last attempt version value of the most\r |
215 | recent FMP capsule update.\r | |
b0bacc00 KM |
216 | **/\r |
217 | VOID\r | |
218 | SetLastAttemptVersionInVariable (\r | |
67c1e5ee EJ |
219 | IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private,\r |
220 | IN UINT32 LastAttemptVersion\r | |
b0bacc00 KM |
221 | );\r |
222 | \r | |
223 | /**\r | |
224 | Locks all the UEFI Variables that use gEfiCallerIdGuid of the currently\r | |
225 | executing module.\r | |
226 | \r | |
67c1e5ee EJ |
227 | @param[in] Private Private context structure for the managed controller.\r |
228 | \r | |
229 | @retval EFI_SUCCESS All UEFI variables are locked.\r | |
230 | @retval EFI_UNSUPPORTED Variable Lock Protocol not found.\r | |
231 | @retval Other One of the UEFI variables could not be locked.\r | |
b0bacc00 KM |
232 | **/\r |
233 | EFI_STATUS\r | |
234 | LockAllFmpVariables (\r | |
67c1e5ee | 235 | IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private\r |
b0bacc00 KM |
236 | );\r |
237 | \r | |
238 | #endif\r |