1 /** @file 2 3 The internal header file includes the common header files, defines 4 internal structure and functions used by EmuVariable module. 5 6 Copyright (c) 2006 - 2011, Intel Corporation. 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 #ifndef _VARIABLE_H_ 18 #define _VARIABLE_H_ 19 20 #include <Uefi.h> 21 22 #include <Protocol/VariableWrite.h> 23 #include <Protocol/Variable.h> 24 25 #include <Library/BaseMemoryLib.h> 26 #include <Library/MemoryAllocationLib.h> 27 #include <Library/DebugLib.h> 28 #include <Library/UefiRuntimeLib.h> 29 #include <Library/UefiDriverEntryPoint.h> 30 #include <Library/UefiBootServicesTableLib.h> 31 #include <Library/UefiLib.h> 32 #include <Library/BaseLib.h> 33 #include <Library/PcdLib.h> 34 #include <Library/HobLib.h> 35 #include <Guid/VariableFormat.h> 36 #include <Guid/GlobalVariable.h> 37 38 #include <Guid/EventGroup.h> 39 40 #define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER)) 41 42 /// 43 /// The size of a 3 character ISO639 language code. 44 /// 45 #define ISO_639_2_ENTRY_SIZE 3 46 47 typedef enum { 48 Physical, 49 Virtual 50 } VARIABLE_POINTER_TYPE; 51 52 typedef struct { 53 VARIABLE_HEADER *CurrPtr; 54 VARIABLE_HEADER *EndPtr; 55 VARIABLE_HEADER *StartPtr; 56 BOOLEAN Volatile; 57 } VARIABLE_POINTER_TRACK; 58 59 typedef struct { 60 EFI_PHYSICAL_ADDRESS VolatileVariableBase; 61 EFI_PHYSICAL_ADDRESS NonVolatileVariableBase; 62 EFI_LOCK VariableServicesLock; 63 } VARIABLE_GLOBAL; 64 65 typedef struct { 66 VARIABLE_GLOBAL VariableGlobal[2]; 67 UINTN VolatileLastVariableOffset; 68 UINTN NonVolatileLastVariableOffset; 69 UINTN CommonVariableTotalSize; 70 UINTN HwErrVariableTotalSize; 71 CHAR8 *PlatformLangCodes; 72 CHAR8 *LangCodes; 73 CHAR8 *PlatformLang; 74 CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1]; 75 } ESAL_VARIABLE_GLOBAL; 76 77 /// 78 /// Don't use module globals after the SetVirtualAddress map is signaled 79 /// 80 extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal; 81 82 /** 83 Initializes variable store area for non-volatile and volatile variable. 84 85 This function allocates and initializes memory space for global context of ESAL 86 variable service and variable store area for non-volatile and volatile variable. 87 88 @param ImageHandle The Image handle of this driver. 89 @param SystemTable The pointer of EFI_SYSTEM_TABLE. 90 91 @retval EFI_SUCCESS Function successfully executed. 92 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. 93 94 **/ 95 EFI_STATUS 96 EFIAPI 97 VariableCommonInitialize ( 98 IN EFI_HANDLE ImageHandle, 99 IN EFI_SYSTEM_TABLE *SystemTable 100 ); 101 102 /** 103 Entry point of EmuVariable service module. 104 105 This function is the entry point of EmuVariable service module. 106 It registers all interfaces of Variable Services, initializes 107 variable store for non-volatile and volatile variables, and registers 108 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event. 109 110 @param ImageHandle The Image handle of this driver. 111 @param SystemTable The pointer of EFI_SYSTEM_TABLE. 112 113 @retval EFI_SUCCESS Variable service successfully initialized. 114 115 **/ 116 EFI_STATUS 117 EFIAPI 118 VariableServiceInitialize ( 119 IN EFI_HANDLE ImageHandle, 120 IN EFI_SYSTEM_TABLE *SystemTable 121 ); 122 123 /** 124 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE. 125 126 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event. 127 It convers pointer to new virtual address. 128 129 @param Event Event whose notification function is being invoked. 130 @param Context Pointer to the notification function's context. 131 132 **/ 133 VOID 134 EFIAPI 135 VariableClassAddressChangeEvent ( 136 IN EFI_EVENT Event, 137 IN VOID *Context 138 ); 139 140 /** 141 This code finds variable in storage blocks (Volatile or Non-Volatile). 142 143 @param VariableName A Null-terminated Unicode string that is the name of 144 the vendor's variable. 145 @param VendorGuid A unique identifier for the vendor. 146 @param Attributes If not NULL, a pointer to the memory location to return the 147 attributes bitmask for the variable. 148 @param DataSize Size of Data found. If size is less than the 149 data, this value contains the required size. 150 @param Data On input, the size in bytes of the return Data buffer. 151 On output, the size of data returned in Data. 152 @param Global Pointer to VARIABLE_GLOBAL structure 153 154 @retval EFI_SUCCESS The function completed successfully. 155 @retval EFI_NOT_FOUND The variable was not found. 156 @retval EFI_BUFFER_TOO_SMALL DataSize is too small for the result. DataSize has 157 been updated with the size needed to complete the request. 158 @retval EFI_INVALID_PARAMETER VariableName or VendorGuid or DataSize is NULL. 159 160 **/ 161 EFI_STATUS 162 EFIAPI 163 EmuGetVariable ( 164 IN CHAR16 *VariableName, 165 IN EFI_GUID *VendorGuid, 166 OUT UINT32 *Attributes OPTIONAL, 167 IN OUT UINTN *DataSize, 168 OUT VOID *Data, 169 IN VARIABLE_GLOBAL *Global 170 ); 171 172 /** 173 174 This code finds the next available variable. 175 176 @param VariableNameSize Size of the variable. 177 @param VariableName On input, supplies the last VariableName that was returned by GetNextVariableName(). 178 On output, returns the Null-terminated Unicode string of the current variable. 179 @param VendorGuid On input, supplies the last VendorGuid that was returned by GetNextVariableName(). 180 On output, returns the VendorGuid of the current variable. 181 @param Global Pointer to VARIABLE_GLOBAL structure. 182 183 @retval EFI_SUCCESS The function completed successfully. 184 @retval EFI_NOT_FOUND The next variable was not found. 185 @retval EFI_BUFFER_TOO_SMALL VariableNameSize is too small for the result. 186 VariableNameSize has been updated with the size needed to complete the request. 187 @retval EFI_INVALID_PARAMETER VariableNameSize or VariableName or VendorGuid is NULL. 188 189 **/ 190 EFI_STATUS 191 EFIAPI 192 EmuGetNextVariableName ( 193 IN OUT UINTN *VariableNameSize, 194 IN OUT CHAR16 *VariableName, 195 IN OUT EFI_GUID *VendorGuid, 196 IN VARIABLE_GLOBAL *Global 197 ); 198 199 /** 200 201 This code sets variable in storage blocks (Volatile or Non-Volatile). 202 203 @param VariableName A Null-terminated Unicode string that is the name of the vendor's 204 variable. Each VariableName is unique for each 205 VendorGuid. VariableName must contain 1 or more 206 Unicode characters. If VariableName is an empty Unicode 207 string, then EFI_INVALID_PARAMETER is returned. 208 @param VendorGuid A unique identifier for the vendor 209 @param Attributes Attributes bitmask to set for the variable 210 @param DataSize The size in bytes of the Data buffer. A size of zero causes the 211 variable to be deleted. 212 @param Data The contents for the variable 213 @param Global Pointer to VARIABLE_GLOBAL structure 214 @param VolatileOffset The offset of last volatile variable 215 @param NonVolatileOffset The offset of last non-volatile variable 216 217 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as 218 defined by the Attributes. 219 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied, or the 220 DataSize exceeds the maximum allowed, or VariableName is an empty 221 Unicode string, or VendorGuid is NULL. 222 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data. 223 @retval EFI_DEVICE_ERROR The variable could not be saved due to a hardware failure. 224 @retval EFI_WRITE_PROTECTED The variable in question is read-only or cannot be deleted. 225 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found. 226 227 **/ 228 EFI_STATUS 229 EFIAPI 230 EmuSetVariable ( 231 IN CHAR16 *VariableName, 232 IN EFI_GUID *VendorGuid, 233 IN UINT32 Attributes, 234 IN UINTN DataSize, 235 IN VOID *Data, 236 IN VARIABLE_GLOBAL *Global, 237 IN UINTN *VolatileOffset, 238 IN UINTN *NonVolatileOffset 239 ); 240 241 /** 242 243 This code returns information about the EFI variables. 244 245 @param Attributes Attributes bitmask to specify the type of variables 246 on which to return information. 247 @param MaximumVariableStorageSize On output the maximum size of the storage space available for 248 the EFI variables associated with the attributes specified. 249 @param RemainingVariableStorageSize Returns the remaining size of the storage space available for EFI 250 variables associated with the attributes specified. 251 @param MaximumVariableSize Returns the maximum size of an individual EFI variable 252 associated with the attributes specified. 253 @param Global Pointer to VARIABLE_GLOBAL structure. 254 255 @retval EFI_SUCCESS Valid answer returned. 256 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied 257 @retval EFI_UNSUPPORTED The attribute is not supported on this platform, and the 258 MaximumVariableStorageSize, RemainingVariableStorageSize, 259 MaximumVariableSize are undefined. 260 261 **/ 262 EFI_STATUS 263 EFIAPI 264 EmuQueryVariableInfo ( 265 IN UINT32 Attributes, 266 OUT UINT64 *MaximumVariableStorageSize, 267 OUT UINT64 *RemainingVariableStorageSize, 268 OUT UINT64 *MaximumVariableSize, 269 IN VARIABLE_GLOBAL *Global 270 ); 271 272 #endif 273