]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Protocol/BlockIo.h
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Include / Protocol / BlockIo.h
CommitLineData
d1f95000 1/** @file\r
8a7d75b0 2 Block IO protocol as defined in the UEFI 2.0 specification.\r
d1f95000 3\r
4 The Block IO protocol is used to abstract block devices like hard drives,\r
5 DVD-ROMs and floppy drives.\r
6\r
9095d37b 7 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 8 SPDX-License-Identifier: BSD-2-Clause-Patent\r
d1f95000 9\r
d1f95000 10**/\r
11\r
12#ifndef __BLOCK_IO_H__\r
13#define __BLOCK_IO_H__\r
14\r
15#define EFI_BLOCK_IO_PROTOCOL_GUID \\r
16 { \\r
17 0x964e5b21, 0x6459, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \\r
18 }\r
19\r
a6508c05 20typedef struct _EFI_BLOCK_IO_PROTOCOL EFI_BLOCK_IO_PROTOCOL;\r
21\r
99e8ed21 22///\r
23/// Protocol GUID name defined in EFI1.1.\r
9095d37b 24///\r
a6508c05 25#define BLOCK_IO_PROTOCOL EFI_BLOCK_IO_PROTOCOL_GUID\r
26\r
99e8ed21 27///\r
28/// Protocol defined in EFI1.1.\r
9095d37b 29///\r
a6508c05 30typedef EFI_BLOCK_IO_PROTOCOL EFI_BLOCK_IO;\r
d1f95000 31\r
32/**\r
33 Reset the Block Device.\r
34\r
f1004231 35 @param This Indicates a pointer to the calling context.\r
d1f95000 36 @param ExtendedVerification Driver may perform diagnostics on reset.\r
37\r
38 @retval EFI_SUCCESS The device was reset.\r
39 @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r
40 not be reset.\r
41\r
42**/\r
43typedef\r
44EFI_STATUS\r
8b13229b 45(EFIAPI *EFI_BLOCK_RESET)(\r
d1f95000 46 IN EFI_BLOCK_IO_PROTOCOL *This,\r
47 IN BOOLEAN ExtendedVerification\r
ed66e1bc 48 );\r
d1f95000 49\r
50/**\r
51 Read BufferSize bytes from Lba into Buffer.\r
52\r
f1004231 53 @param This Indicates a pointer to the calling context.\r
d1f95000 54 @param MediaId Id of the media, changes every time the media is replaced.\r
55 @param Lba The starting Logical Block Address to read from\r
56 @param BufferSize Size of Buffer, must be a multiple of device block size.\r
f1004231
LG
57 @param Buffer A pointer to the destination buffer for the data. The caller is\r
58 responsible for either having implicit or explicit ownership of the buffer.\r
d1f95000 59\r
60 @retval EFI_SUCCESS The data was read correctly from the device.\r
61 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r
62 @retval EFI_NO_MEDIA There is no media in the device.\r
63 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.\r
64 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r
9095d37b 65 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
f1004231 66 or the buffer is not on proper alignment.\r
d1f95000 67\r
68**/\r
69typedef\r
70EFI_STATUS\r
8b13229b 71(EFIAPI *EFI_BLOCK_READ)(\r
d1f95000 72 IN EFI_BLOCK_IO_PROTOCOL *This,\r
73 IN UINT32 MediaId,\r
74 IN EFI_LBA Lba,\r
75 IN UINTN BufferSize,\r
76 OUT VOID *Buffer\r
ed66e1bc 77 );\r
d1f95000 78\r
79/**\r
80 Write BufferSize bytes from Lba into Buffer.\r
81\r
f1004231
LG
82 @param This Indicates a pointer to the calling context.\r
83 @param MediaId The media ID that the write request is for.\r
84 @param Lba The starting logical block address to be written. The caller is\r
85 responsible for writing to only legitimate locations.\r
d1f95000 86 @param BufferSize Size of Buffer, must be a multiple of device block size.\r
f1004231 87 @param Buffer A pointer to the source buffer for the data.\r
d1f95000 88\r
89 @retval EFI_SUCCESS The data was written correctly to the device.\r
90 @retval EFI_WRITE_PROTECTED The device can not be written to.\r
91 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r
92 @retval EFI_NO_MEDIA There is no media in the device.\r
93 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r
94 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r
9095d37b 95 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r
f1004231 96 or the buffer is not on proper alignment.\r
d1f95000 97\r
98**/\r
99typedef\r
100EFI_STATUS\r
8b13229b 101(EFIAPI *EFI_BLOCK_WRITE)(\r
d1f95000 102 IN EFI_BLOCK_IO_PROTOCOL *This,\r
103 IN UINT32 MediaId,\r
104 IN EFI_LBA Lba,\r
105 IN UINTN BufferSize,\r
106 IN VOID *Buffer\r
ed66e1bc 107 );\r
d1f95000 108\r
109/**\r
110 Flush the Block Device.\r
111\r
f1004231 112 @param This Indicates a pointer to the calling context.\r
d1f95000 113\r
114 @retval EFI_SUCCESS All outstanding data was written to the device\r
115 @retval EFI_DEVICE_ERROR The device reported an error while writting back the data\r
116 @retval EFI_NO_MEDIA There is no media in the device.\r
117\r
118**/\r
119typedef\r
120EFI_STATUS\r
8b13229b 121(EFIAPI *EFI_BLOCK_FLUSH)(\r
d1f95000 122 IN EFI_BLOCK_IO_PROTOCOL *This\r
ed66e1bc 123 );\r
d1f95000 124\r
125/**\r
126 Block IO read only mode data and updated only via members of BlockIO\r
d1f95000 127**/\r
128typedef struct {\r
8b6c989b 129 ///\r
130 /// The curent media Id. If the media changes, this value is changed.\r
131 ///\r
9095d37b
LG
132 UINT32 MediaId;\r
133\r
8b6c989b 134 ///\r
135 /// TRUE if the media is removable; otherwise, FALSE.\r
9095d37b 136 ///\r
4ca9b6c4 137 BOOLEAN RemovableMedia;\r
9095d37b 138\r
8b6c989b 139 ///\r
140 /// TRUE if there is a media currently present in the device;\r
141 /// othersise, FALSE. THis field shows the media present status\r
9095d37b 142 /// as of the most recent ReadBlocks() or WriteBlocks() call.\r
8b6c989b 143 ///\r
4ca9b6c4 144 BOOLEAN MediaPresent;\r
8b6c989b 145\r
146 ///\r
147 /// TRUE if LBA 0 is the first block of a partition; otherwise\r
148 /// FALSE. For media with only one partition this would be TRUE.\r
149 ///\r
4ca9b6c4 150 BOOLEAN LogicalPartition;\r
9095d37b 151\r
8b6c989b 152 ///\r
153 /// TRUE if the media is marked read-only otherwise, FALSE.\r
154 /// This field shows the read-only status as of the most recent WriteBlocks () call.\r
155 ///\r
4ca9b6c4 156 BOOLEAN ReadOnly;\r
9095d37b 157\r
8b6c989b 158 ///\r
159 /// TRUE if the WriteBlock () function caches write data.\r
160 ///\r
9095d37b
LG
161 BOOLEAN WriteCaching;\r
162\r
8b6c989b 163 ///\r
164 /// The intrinsic block size of the device. If the media changes, then\r
9095d37b 165 /// this field is updated.\r
8b6c989b 166 ///\r
9095d37b
LG
167 UINT32 BlockSize;\r
168\r
8b6c989b 169 ///\r
170 /// Supplies the alignment requirement for any buffer to read or write block(s).\r
171 ///\r
9095d37b
LG
172 UINT32 IoAlign;\r
173\r
8b6c989b 174 ///\r
175 /// The last logical block address on the device.\r
9095d37b 176 /// If the media changes, then this field is updated.\r
8b6c989b 177 ///\r
9095d37b 178 EFI_LBA LastBlock;\r
312bc8f8 179\r
180 ///\r
181 /// Only present if EFI_BLOCK_IO_PROTOCOL.Revision is greater than or equal to\r
9095d37b
LG
182 /// EFI_BLOCK_IO_PROTOCOL_REVISION2. Returns the first LBA is aligned to\r
183 /// a physical block boundary.\r
312bc8f8 184 ///\r
185 EFI_LBA LowestAlignedLba;\r
186\r
187 ///\r
188 /// Only present if EFI_BLOCK_IO_PROTOCOL.Revision is greater than or equal to\r
9095d37b 189 /// EFI_BLOCK_IO_PROTOCOL_REVISION2. Returns the number of logical blocks\r
312bc8f8 190 /// per physical block.\r
191 ///\r
192 UINT32 LogicalBlocksPerPhysicalBlock;\r
b8a62661
RN
193\r
194 ///\r
195 /// Only present if EFI_BLOCK_IO_PROTOCOL.Revision is greater than or equal to\r
196 /// EFI_BLOCK_IO_PROTOCOL_REVISION3. Returns the optimal transfer length\r
197 /// granularity as a number of logical blocks.\r
198 ///\r
199 UINT32 OptimalTransferLengthGranularity;\r
d1f95000 200} EFI_BLOCK_IO_MEDIA;\r
201\r
202#define EFI_BLOCK_IO_PROTOCOL_REVISION 0x00010000\r
312bc8f8 203#define EFI_BLOCK_IO_PROTOCOL_REVISION2 0x00020001\r
b8a62661 204#define EFI_BLOCK_IO_PROTOCOL_REVISION3 0x00020031\r
8b6c989b 205\r
206///\r
207/// Revision defined in EFI1.1.\r
9095d37b 208///\r
a6508c05 209#define EFI_BLOCK_IO_INTERFACE_REVISION EFI_BLOCK_IO_PROTOCOL_REVISION\r
d1f95000 210\r
44717a39 211///\r
212/// This protocol provides control over block devices.\r
213///\r
d1f95000 214struct _EFI_BLOCK_IO_PROTOCOL {\r
8b6c989b 215 ///\r
216 /// The revision to which the block IO interface adheres. All future\r
217 /// revisions must be backwards compatible. If a future version is not\r
218 /// back wards compatible, it is not the same GUID.\r
219 ///\r
d1f95000 220 UINT64 Revision;\r
44717a39 221 ///\r
222 /// Pointer to the EFI_BLOCK_IO_MEDIA data for this device.\r
223 ///\r
d1f95000 224 EFI_BLOCK_IO_MEDIA *Media;\r
225\r
226 EFI_BLOCK_RESET Reset;\r
227 EFI_BLOCK_READ ReadBlocks;\r
228 EFI_BLOCK_WRITE WriteBlocks;\r
229 EFI_BLOCK_FLUSH FlushBlocks;\r
230\r
231};\r
232\r
233extern EFI_GUID gEfiBlockIoProtocolGuid;\r
234\r
235#endif\r