SerializeVariablesLib.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /** @file
  2. Serialize & Deserialize UEFI Variables
  3. Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __SERIALIZE_VARIABLES_LIB__
  7. #define __SERIALIZE_VARIABLES_LIB__
  8. /**
  9. Callback function for each variable
  10. @param[in] Context - Context as sent to the iteration function
  11. @param[in] VariableName - Refer to RuntimeServices GetNextVariableName
  12. @param[in] VendorGuid - Refer to RuntimeServices GetNextVariableName
  13. @param[in] Attributes - Refer to RuntimeServices GetVariable
  14. @param[in] DataSize - Refer to RuntimeServices GetVariable
  15. @param[in] Data - Refer to RuntimeServices GetVariable
  16. @retval RETURN_SUCCESS Continue iterating through the variables
  17. @return Any RETURN_ERROR Stop iterating through the variables
  18. **/
  19. typedef
  20. RETURN_STATUS
  21. (EFIAPI *VARIABLE_SERIALIZATION_ITERATION_CALLBACK)(
  22. IN VOID *Context,
  23. IN CHAR16 *VariableName,
  24. IN EFI_GUID *VendorGuid,
  25. IN UINT32 Attributes,
  26. IN UINTN DataSize,
  27. IN VOID *Data
  28. );
  29. /**
  30. Creates a new variable serialization instance
  31. @param[out] Handle - Handle for a variable serialization instance
  32. @retval RETURN_SUCCESS - The variable serialization instance was
  33. successfully created.
  34. @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
  35. create the variable serialization instance.
  36. **/
  37. RETURN_STATUS
  38. EFIAPI
  39. SerializeVariablesNewInstance (
  40. OUT EFI_HANDLE *Handle
  41. );
  42. /**
  43. Free memory associated with a variable serialization instance
  44. @param[in] Handle - Handle for a variable serialization instance
  45. @retval RETURN_SUCCESS - The variable serialization instance was
  46. successfully freed.
  47. @retval RETURN_INVALID_PARAMETER - Handle was not a valid
  48. variable serialization instance.
  49. **/
  50. RETURN_STATUS
  51. EFIAPI
  52. SerializeVariablesFreeInstance (
  53. IN EFI_HANDLE Handle
  54. );
  55. /**
  56. Creates a new variable serialization instance using the given
  57. binary representation of the variables to fill the new instance
  58. @param[out] Handle - Handle for a variable serialization instance
  59. @param[in] Buffer - A buffer with the serialized representation
  60. of the variables. Must be the same format as produced
  61. by SerializeVariablesToBuffer.
  62. @param[in] Size - This is the size of the binary representation
  63. of the variables.
  64. @retval RETURN_SUCCESS - The binary representation was successfully
  65. imported into a new variable serialization instance
  66. @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
  67. create the new variable serialization instance
  68. **/
  69. RETURN_STATUS
  70. EFIAPI
  71. SerializeVariablesNewInstanceFromBuffer (
  72. OUT EFI_HANDLE *Handle,
  73. IN VOID *Buffer,
  74. IN UINTN Size
  75. );
  76. /**
  77. Iterates all variables found with RuntimeServices GetNextVariableName
  78. @param[in] CallbackFunction - Function called for each variable instance
  79. @param[in] Context - Passed to each call of CallbackFunction
  80. @retval RETURN_SUCCESS - All variables were iterated without the
  81. CallbackFunction returning an error
  82. @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
  83. iterate through the variables
  84. @return Any of RETURN_ERROR indicates an error reading the variable
  85. or an error was returned from CallbackFunction
  86. **/
  87. RETURN_STATUS
  88. EFIAPI
  89. SerializeVariablesIterateSystemVariables (
  90. IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction,
  91. IN VOID *Context
  92. );
  93. /**
  94. Iterates all variables found in the variable serialization instance
  95. @param[in] Handle - Handle for a variable serialization instance
  96. @param[in] CallbackFunction - Function called for each variable instance
  97. @param[in] Context - Passed to each call of CallbackFunction
  98. @retval RETURN_SUCCESS - All variables were iterated without the
  99. CallbackFunction returning an error
  100. @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
  101. iterate through the variables
  102. @return Any of RETURN_ERROR indicates an error reading the variable
  103. or an error was returned from CallbackFunction
  104. **/
  105. RETURN_STATUS
  106. EFIAPI
  107. SerializeVariablesIterateInstanceVariables (
  108. IN EFI_HANDLE Handle,
  109. IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction,
  110. IN VOID *Context
  111. );
  112. /**
  113. Sets all variables found in the variable serialization instance
  114. @param[in] Handle - Handle for a variable serialization instance
  115. @retval RETURN_SUCCESS - All variables were set successfully
  116. @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
  117. set all the variables
  118. @return Any of RETURN_ERROR indicates an error reading the variables
  119. or in attempting to set a variable
  120. **/
  121. RETURN_STATUS
  122. EFIAPI
  123. SerializeVariablesSetSerializedVariables (
  124. IN EFI_HANDLE Handle
  125. );
  126. /**
  127. Adds a variable to the variable serialization instance
  128. @param[in] Handle - Handle for a variable serialization instance
  129. @param[in] VariableName - Refer to RuntimeServices GetVariable
  130. @param[in] VendorGuid - Refer to RuntimeServices GetVariable
  131. @param[in] Attributes - Refer to RuntimeServices GetVariable
  132. @param[in] DataSize - Refer to RuntimeServices GetVariable
  133. @param[in] Data - Refer to RuntimeServices GetVariable
  134. @retval RETURN_SUCCESS - All variables were set successfully
  135. @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
  136. add the variable
  137. **/
  138. RETURN_STATUS
  139. EFIAPI
  140. SerializeVariablesAddVariable (
  141. IN EFI_HANDLE Handle,
  142. IN CHAR16 *VariableName,
  143. IN EFI_GUID *VendorGuid,
  144. IN UINT32 Attributes,
  145. IN UINTN DataSize,
  146. IN VOID *Data
  147. );
  148. /**
  149. Serializes the variables known to this instance into the
  150. provided buffer.
  151. @param[in] Handle - Handle for a variable serialization instance
  152. @param[out] Buffer - A buffer to store the binary representation
  153. of the variables.
  154. @param[in,out] Size - On input this is the size of the buffer.
  155. On output this is the size of the binary representation
  156. of the variables.
  157. @retval RETURN_SUCCESS - The binary representation was successfully
  158. completed and returned in the buffer.
  159. @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
  160. save the variables to the buffer.
  161. @retval RETURN_INVALID_PARAMETER - Handle was not a valid
  162. variable serialization instance or
  163. Size or Buffer were NULL.
  164. **/
  165. RETURN_STATUS
  166. EFIAPI
  167. SerializeVariablesToBuffer (
  168. IN EFI_HANDLE Handle,
  169. OUT VOID *Buffer,
  170. IN OUT UINTN *Size
  171. );
  172. #endif