1
0

fvblock.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*++
  2. Copyright (c) 2014 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. fvblock.h
  9. Abstract:
  10. This header contains definitions for the UEFI Firmware Volume Block
  11. Protocol.
  12. Author:
  13. Evan Green 11-Mar-2014
  14. --*/
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. //
  19. // ---------------------------------------------------------------- Definitions
  20. //
  21. //
  22. // This defines the version 2 GUID.
  23. //
  24. #define EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID \
  25. { \
  26. 0x8F644FA9, 0xE850, 0x4DB1, \
  27. {0x9C, 0xE2, 0x0B, 0x44, 0x69, 0x8E, 0x8D, 0xA4} \
  28. }
  29. #define EFI_LBA_LIST_TERMINATOR 0xFFFFFFFFFFFFFFFFULL
  30. //
  31. // ------------------------------------------------------ Data Type Definitions
  32. //
  33. typedef struct _EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
  34. EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL;
  35. typedef
  36. EFI_STATUS
  37. (EFIAPI *EFI_FVB_GET_ATTRIBUTES) (
  38. CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
  39. EFI_FVB_ATTRIBUTES *Attributes
  40. );
  41. /*++
  42. Routine Description:
  43. This routine retrieves the attributes and current settings of the block
  44. device.
  45. Arguments:
  46. This - Supplies the protocol instance.
  47. Attributes - Supplies a pointer where the attributes will be returne.
  48. Return Value:
  49. EFI Status code.
  50. --*/
  51. typedef
  52. EFI_STATUS
  53. (EFIAPI *EFI_FVB_SET_ATTRIBUTES) (
  54. CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
  55. EFI_FVB_ATTRIBUTES *Attributes
  56. );
  57. /*++
  58. Routine Description:
  59. This routine sets configurable firmware volume attributes and returns the
  60. new settings.
  61. Arguments:
  62. This - Supplies the protocol instance.
  63. Attributes - Supplies a pointer that on input contains the attributes to
  64. set. On output, it contains the new settings.
  65. Return Value:
  66. EFI_SUCCESS on success.
  67. EFI_INVALID_PARAMETER if the requested attributes are in conflict with the
  68. capabilities as declared in the firmware volume header.
  69. --*/
  70. typedef
  71. EFI_STATUS
  72. (EFIAPI *EFI_FVB_GET_PHYSICAL_ADDRESS) (
  73. CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
  74. EFI_PHYSICAL_ADDRESS *Address
  75. );
  76. /*++
  77. Routine Description:
  78. This routine retrieves the base address of a memory-mapped firmware volume.
  79. This function should only be called for memory-mapped firmware volumes.
  80. Arguments:
  81. This - Supplies the protocol instance.
  82. Address - Supplies a pointer where the physical address of the firmware
  83. volume will be returned on success.
  84. Return Value:
  85. EFI_SUCCESS on success.
  86. EFI_UNSUPPORTED if the firmware volume is not memory mapped.
  87. --*/
  88. typedef
  89. EFI_STATUS
  90. (EFIAPI *EFI_FVB_GET_BLOCK_SIZE) (
  91. CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
  92. EFI_LBA Lba,
  93. UINTN *BlockSize,
  94. UINTN *NumberOfBlocks
  95. );
  96. /*++
  97. Routine Description:
  98. This routine retrieves the size of the requested block. It also returns the
  99. number of additional blocks with the identical size. This routine is used
  100. to retrieve the block map.
  101. Arguments:
  102. This - Supplies the protocol instance.
  103. Lba - Supplies the block for which to return the size.
  104. BlockSize - Supplies a pointer where the size of the block is returned on
  105. success.
  106. NumberOfBlocks - Supplies a pointer where the number of consecutive blocks
  107. with the same block size is returned on success.
  108. Return Value:
  109. EFI_SUCCESS on success.
  110. EFI_INVALID_PARAMETER if the requested block address is out of range.
  111. --*/
  112. typedef
  113. EFI_STATUS
  114. (EFIAPI *EFI_FVB_READ) (
  115. CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
  116. EFI_LBA Lba,
  117. UINTN Offset,
  118. UINTN *ByteCount,
  119. UINT8 *Buffer
  120. );
  121. /*++
  122. Routine Description:
  123. This routine reads the requested number of bytes from the requested block
  124. and stores them in the provided buffer. Implementations should be mindful
  125. that the firmware volume might be in the ReadDisabled state. If it is in
  126. this state, this function must return the status code EFI_ACCESS_DENIED
  127. without modifying the contents of the buffer. This function must also
  128. prevent spanning block boundaries. If a read is requested that would span a
  129. block boundary, the read must read up to the boundary but not beyond. The
  130. output byte count parameter must be set to correctly indicate the number of
  131. bytes actually read. The caller must be aware that a read may be partially
  132. completed.
  133. Arguments:
  134. This - Supplies the protocol instance.
  135. Lba - Supplies the starting block address from which to read.
  136. Offset - Supplies the offset into the block at which to begin reading.
  137. ByteCount - Supplies a pointer that on input contains the size of the
  138. read buffer in bytes. On output, will contain the number of bytes read.
  139. Buffer - Supplies a pointer to the caller-allocated buffer where the read
  140. data will be returned.
  141. Return Value:
  142. EFI_SUCCESS on success.
  143. EFI_BAD_BUFFER_SIZE if the read attempted to cross an LBA boundary. On
  144. output, the byte count will contain the number of bytes returned in the
  145. buffer.
  146. EFI_ACCESS_DENIED if the firmware volume is in the ReadDisabled state.
  147. EFI_DEVICE_ERROR if the block device is not functioning properly.
  148. --*/
  149. typedef
  150. EFI_STATUS
  151. (EFIAPI *EFI_FVB_WRITE) (
  152. CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
  153. EFI_LBA Lba,
  154. UINTN Offset,
  155. UINTN *ByteCount,
  156. UINT8 *Buffer
  157. );
  158. /*++
  159. Routine Description:
  160. This routine writes the specified number of bytes from the provided buffer
  161. to the specified block and offset. If the firmware volume is sticky write,
  162. the caller must ensure that all the bits of the specified range to write
  163. are in the EFI_FVB_ERASE_POLARITY state before calling the write function,
  164. or else the result will be unpredictable. This unpredictability arises
  165. because, for a sticky-write firmware volume, a write may negate a bit in
  166. the EFI_FVB_ERASE_POLARITY state but cannot flip it back again. Before
  167. calling the write function, it is recommended for the caller to first call
  168. the erase blocks function to erase the specified block to write. A block
  169. erase cycle will transition bits from the (NOT)EFI_FVB_ERASE_POLARITY state
  170. back to the EFI_FVB_ERASE_POLARITY state. Implementations should be mindful
  171. that the firmware volume might be in the WriteDisabled state. If it is in
  172. this state, this function must return the status code EFI_ACCESS_DENIED
  173. without modifying the contents of the firmware volume. The write function
  174. must also prevent spanning block boundaries. If a write is requested that
  175. spans a block boundary, the write must store up to the boundary but not
  176. beyond. The output byte count parameter must be set to correctly indicate
  177. the number of bytes actually written. The caller must be aware that a write
  178. may be partially completed. All writes, partial or otherwise, must be fully
  179. flushed to the hardware before the write routine returns.
  180. Arguments:
  181. This - Supplies the protocol instance.
  182. Lba - Supplies the starting block address from which to write.
  183. Offset - Supplies the offset into the block at which to begin writing.
  184. ByteCount - Supplies a pointer that on input contains the size of the
  185. write buffer in bytes. On output, will contain the number of bytes
  186. written.
  187. Buffer - Supplies a pointer to the caller-allocated buffer containing the
  188. data to write.
  189. Return Value:
  190. EFI_SUCCESS on success.
  191. EFI_BAD_BUFFER_SIZE if the write attempted to cross an LBA boundary. On
  192. output, the byte count will contain the number of bytes written.
  193. EFI_ACCESS_DENIED if the firmware volume is in the WriteDisabled state.
  194. EFI_DEVICE_ERROR if the block device is not functioning properly.
  195. --*/
  196. typedef
  197. EFI_STATUS
  198. (EFIAPI *EFI_FVB_ERASE_BLOCKS) (
  199. CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
  200. ...
  201. );
  202. /*++
  203. Routine Description:
  204. This routine erases one or more blocks as denoted by the variable argument
  205. list. The entire parameter list of blocks must be verified before erasing
  206. any blocks. If a block is requested that does not exist within the
  207. associated firmware volume (it has a larger index than the last block of
  208. the firmware volume), this function must return the status code
  209. EFI_INVALID_PARAMETER without modifying the contents of the firmware
  210. volume. Implementations should be mindful that the firmware volume might be
  211. in the WriteDisabled state. If it is in this state, this function must
  212. return the status code EFI_ACCESS_DENIED without modifying the contents of
  213. the firmware volume. All calls to erase blocks must be fully flushed to the
  214. hardware before this routine returns.
  215. Arguments:
  216. This - Supplies the protocol instance.
  217. ... - Supplies the variable argument list, which is a list of tuples. Each
  218. tuple describes a range of LBAs to erase and consists of the following:
  219. 1) an EFI_LBA that indicates the starting LBA, and 2) a UINTN that
  220. indicates the number of blocks to erase. The list is terminated with
  221. an EFI_LBA_LIST_TERMINATOR. For example, to erase blocks 5-7 and
  222. 10-11, this list would contain (5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR).
  223. Return Value:
  224. EFI_SUCCESS on success.
  225. EFI_ACCESS_DENIED if the firmware volume is in the WriteDisabled state.
  226. EFI_INVALID_PARAMETER if one or more of the LBAs listed in the variable
  227. argument list do not exist on the firmware block device.
  228. EFI_DEVICE_ERROR if the block device is not functioning properly.
  229. --*/
  230. /*++
  231. Structure Description:
  232. This structure defines the Firmware Volume Block Protocol. It is a
  233. low-level interface to a firmware volume. File-level access to a firmware
  234. volume should not be done using the Firmware Volume Block Protocol. Normal
  235. access to a firmware volume must use the Firmware Volume Protocol.
  236. Typically, only the file system driver that produces the Firmware Volume
  237. Protocol will bind to the Firmware Volume Block Protocol.
  238. Members:
  239. GetAttributes - Stores a pointer to a function used to get block device
  240. attributes.
  241. SetAttributes - Stores a pointer to a function used to set block device
  242. attributes.
  243. GetPhysicalAddress - Stores a pointer to a function used to get the
  244. physical memory address of a memory-mapped firmware block device.
  245. GetBlockSize - Stores a pointer to a function used to get the size of a
  246. block at a given LBA.
  247. Read - Stores a pointer to a function used to read blocks from the device.
  248. Write - Stores a pointer to a function used to write blocks to the device.
  249. EraseBlocks - Stores a pointer to a function used to erase blocks on the
  250. device.
  251. ParentHandle - Stores the handle of the parent firmware volume.
  252. --*/
  253. struct _EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL {
  254. EFI_FVB_GET_ATTRIBUTES GetAttributes;
  255. EFI_FVB_SET_ATTRIBUTES SetAttributes;
  256. EFI_FVB_GET_PHYSICAL_ADDRESS GetPhysicalAddress;
  257. EFI_FVB_GET_BLOCK_SIZE GetBlockSize;
  258. EFI_FVB_READ Read;
  259. EFI_FVB_WRITE Write;
  260. EFI_FVB_ERASE_BLOCKS EraseBlocks;
  261. EFI_HANDLE ParentHandle;
  262. };
  263. //
  264. // -------------------------------------------------------------------- Globals
  265. //
  266. //
  267. // -------------------------------------------------------- Function Prototypes
  268. //