rtlib.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. rtlib.h
  5. Abstract:
  6. This header contains internal definitions for the UEFI runtime library.
  7. Author:
  8. Evan Green 18-Mar-2014
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. #include <uefifw.h>
  14. #include "shortcut.h"
  15. //
  16. // ---------------------------------------------------------------- Definitions
  17. //
  18. //
  19. // ------------------------------------------------------ Data Type Definitions
  20. //
  21. //
  22. // -------------------------------------------------------------------- Globals
  23. //
  24. //
  25. // -------------------------------------------------------- Function Prototypes
  26. //
  27. //
  28. // Variable services
  29. //
  30. EFIAPI
  31. EFI_STATUS
  32. EfiCoreSetVariable (
  33. CHAR16 *VariableName,
  34. EFI_GUID *VendorGuid,
  35. UINT32 Attributes,
  36. UINTN DataSize,
  37. VOID *Data
  38. );
  39. /*++
  40. Routine Description:
  41. This routine sets the value of a variable.
  42. Arguments:
  43. VariableName - Supplies a pointer to a null-terminated string containing
  44. the name of the vendor's variable. Each variable name is unique for a
  45. particular vendor GUID. A variable name must be at least one character
  46. in length.
  47. VendorGuid - Supplies a pointer to the unique GUID for the vendor.
  48. Attributes - Supplies the attributes for this variable. See EFI_VARIABLE_*
  49. definitions.
  50. DataSize - Supplies the size of the data buffer. Unless the
  51. EFI_VARIABLE_APPEND_WRITE, EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
  52. EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a
  53. size of zero causes the variable to be deleted. When the
  54. EFI_VARIABLE_APPEND_WRITE attribute is set, then a set variable call
  55. with a data size of zero will not cause any change to the variable
  56. value (the timestamp associated with the variable may be updated
  57. however even if no new data value is provided,see the description of
  58. the EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the
  59. data size will not be zero since the EFI_VARIABLE_AUTHENTICATION_2
  60. descriptor will be populated).
  61. Data - Supplies the contents of the variable.
  62. Return Value:
  63. EFI_SUCCESS on success.
  64. EFI_NOT_FOUND if the variable being updated or deleted was not found.
  65. EFI_INVALID_PARAMETER if an invalid combination of attribute bits, name,
  66. and GUID was suplied, data size exceeds the maximum, or the variable name
  67. is an empty string.
  68. EFI_DEVICE_ERROR if a hardware error occurred trying to access the variable.
  69. EFI_WRITE_PROTECTED if the variable is read-only or cannot be deleted.
  70. EFI_SECURITY_VIOLATION if variable could not be written due to
  71. EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS or
  72. EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the
  73. authorization information does NOT pass the validation check carried out by
  74. the firmware.
  75. --*/
  76. EFIAPI
  77. EFI_STATUS
  78. EfiCoreGetNextVariableName (
  79. UINTN *VariableNameSize,
  80. CHAR16 *VariableName,
  81. EFI_GUID *VendorGuid
  82. );
  83. /*++
  84. Routine Description:
  85. This routine enumerates the current variable names.
  86. Arguments:
  87. VariableNameSize - Supplies a pointer that on input contains the size of
  88. the variable name buffer. On output, will contain the size of the
  89. variable name.
  90. VariableName - Supplies a pointer that on input contains the last variable
  91. name that was returned. On output, returns the null terminated string
  92. of the current variable.
  93. VendorGuid - Supplies a pointer that on input contains the last vendor GUID
  94. returned by this routine. On output, returns the vendor GUID of the
  95. current variable.
  96. Return Value:
  97. EFI_SUCCESS on success.
  98. EFI_NOT_FOUND if the next variable was not found.
  99. EFI_BUFFER_TOO_SMALL if the supplied buffer is not big enough.
  100. EFI_INVALID_PARAMETER if the variable name, vendor GUID, or data size is
  101. NULL.
  102. EFI_DEVICE_ERROR if a hardware error occurred trying to read the variable.
  103. --*/
  104. EFIAPI
  105. EFI_STATUS
  106. EfiCoreGetVariable (
  107. CHAR16 *VariableName,
  108. EFI_GUID *VendorGuid,
  109. UINT32 *Attributes,
  110. UINTN *DataSize,
  111. VOID *Data
  112. );
  113. /*++
  114. Routine Description:
  115. This routine returns the value of a variable.
  116. Arguments:
  117. VariableName - Supplies a pointer to a null-terminated string containing
  118. the name of the vendor's variable.
  119. VendorGuid - Supplies a pointer to the unique GUID for the vendor.
  120. Attributes - Supplies an optional pointer where the attribute mask for the
  121. variable will be returned.
  122. DataSize - Supplies a pointer that on input contains the size of the data
  123. buffer. On output, the actual size of the data will be returned.
  124. Data - Supplies a pointer where the variable value will be returned.
  125. Return Value:
  126. EFI_SUCCESS on success.
  127. EFI_NOT_FOUND if the variable was not found.
  128. EFI_BUFFER_TOO_SMALL if the supplied buffer is not big enough.
  129. EFI_INVALID_PARAMETER if the variable name, vendor GUID, or data size is
  130. NULL.
  131. EFI_DEVICE_ERROR if a hardware error occurred trying to read the variable.
  132. EFI_SECURITY_VIOLATION if the variable could not be retrieved due to an
  133. authentication failure.
  134. --*/
  135. EFIAPI
  136. EFI_STATUS
  137. EfiCoreQueryVariableInfo (
  138. UINT32 Attributes,
  139. UINT64 *MaximumVariableStorageSize,
  140. UINT64 *RemainingVariableStorageSize,
  141. UINT64 *MaximumVariableSize
  142. );
  143. /*++
  144. Routine Description:
  145. This routine returns information about EFI variables.
  146. Arguments:
  147. Attributes - Supplies a bitmask of attributes specifying the type of
  148. variables on which to return information.
  149. MaximumVariableStorageSize - Supplies a pointer where the maximum size of
  150. storage space for EFI variables with the given attributes will be
  151. returned.
  152. RemainingVariableStorageSize - Supplies a pointer where the remaining size
  153. of the storage space available for EFI variables associated with the
  154. attributes specified will be returned.
  155. MaximumVariableSize - Supplies a pointer where the maximum size of an
  156. individual variable will be returned on success.
  157. Return Value:
  158. EFI_SUCCESS if a valid answer was returned.
  159. EFI_UNSUPPORTED if the attribute is not supported on this platform.
  160. EFI_INVALID_PARAMETER if an invalid combination of attributes was supplied.
  161. --*/
  162. EFI_STATUS
  163. EfipCoreInitializeVariableServices (
  164. VOID
  165. );
  166. /*++
  167. Routine Description:
  168. This routine initialize core variable services.
  169. Arguments:
  170. None.
  171. Return Value:
  172. EFI Status code.
  173. --*/
  174. VOID
  175. EfipCoreVariableHandleExitBootServices (
  176. VOID
  177. );
  178. /*++
  179. Routine Description:
  180. This routine is called when leaving boot services.
  181. Arguments:
  182. None.
  183. Return Value:
  184. None.
  185. --*/
  186. VOID
  187. EfipCoreVariableHandleVirtualAddressChange (
  188. VOID
  189. );
  190. /*++
  191. Routine Description:
  192. This routine is called to change from physical to virtual mode.
  193. Arguments:
  194. None.
  195. Return Value:
  196. None.
  197. --*/
  198. //
  199. // Utility functions
  200. //
  201. EFIAPI
  202. VOID
  203. EfiCoreCopyMemory (
  204. VOID *Destination,
  205. VOID *Source,
  206. UINTN Length
  207. );
  208. /*++
  209. Routine Description:
  210. This routine copies the contents of one buffer to another.
  211. Arguments:
  212. Destination - Supplies a pointer to the destination of the copy.
  213. Source - Supplies a pointer to the source of the copy.
  214. Length - Supplies the number of bytes to copy.
  215. Return Value:
  216. None.
  217. --*/
  218. EFIAPI
  219. VOID
  220. EfiCoreSetMemory (
  221. VOID *Buffer,
  222. UINTN Size,
  223. UINT8 Value
  224. );
  225. /*++
  226. Routine Description:
  227. This routine fills a buffer with a specified value.
  228. Arguments:
  229. Buffer - Supplies a pointer to the buffer to fill.
  230. Size - Supplies the size of the buffer in bytes.
  231. Value - Supplies the value to fill the buffer with.
  232. Return Value:
  233. None.
  234. --*/
  235. INTN
  236. EfiCoreCompareMemory (
  237. VOID *FirstBuffer,
  238. VOID *SecondBuffer,
  239. UINTN Length
  240. );
  241. /*++
  242. Routine Description:
  243. This routine compares the contents of two buffers for equality.
  244. Arguments:
  245. FirstBuffer - Supplies a pointer to the first buffer to compare.
  246. SecondBuffer - Supplies a pointer to the second buffer to compare.
  247. Length - Supplies the number of bytes to compare.
  248. Return Value:
  249. 0 if the buffers are identical.
  250. Returns the first mismatched byte as
  251. First[MismatchIndex] - Second[MismatchIndex].
  252. --*/
  253. BOOLEAN
  254. EfiCoreCompareGuids (
  255. EFI_GUID *FirstGuid,
  256. EFI_GUID *SecondGuid
  257. );
  258. /*++
  259. Routine Description:
  260. This routine compares two GUIDs.
  261. Arguments:
  262. FirstGuid - Supplies a pointer to the first GUID.
  263. SecondGuid - Supplies a pointer to the second GUID.
  264. Return Value:
  265. TRUE if the GUIDs are equal.
  266. FALSE if the GUIDs are different.
  267. --*/
  268. UINTN
  269. EfiCoreStringLength (
  270. CHAR16 *String
  271. );
  272. /*++
  273. Routine Description:
  274. This routine returns the length of the given string, in characters (not
  275. bytes).
  276. Arguments:
  277. String - Supplies a pointer to the string.
  278. Return Value:
  279. Returns the number of characters in the string.
  280. --*/
  281. EFIAPI
  282. EFI_STATUS
  283. EfiCoreCalculateCrc32 (
  284. VOID *Data,
  285. UINTN DataSize,
  286. UINT32 *Crc32
  287. );
  288. /*++
  289. Routine Description:
  290. This routine computes the 32-bit CRC for a data buffer.
  291. Arguments:
  292. Data - Supplies a pointer to the buffer to compute the CRC on.
  293. DataSize - Supplies the size of the data buffer in bytes.
  294. Crc32 - Supplies a pointer where the 32-bit CRC will be returned.
  295. Return Value:
  296. EFI_SUCCESS on success.
  297. EFI_INVALID_PARAMETER if any parameter is NULL, or the data size is zero.
  298. --*/