1 /** @file
2   Block IO protocol as defined in the UEFI 2.0 specification.
3 
4   The Block IO protocol is used to abstract block devices like hard drives,
5   DVD-ROMs and floppy drives.
6 
7   Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
8   This program and the accompanying materials
9   are licensed and made available under the terms and conditions of the BSD License
10   which accompanies this distribution.  The full text of the license may be found at
11   http://opensource.org/licenses/bsd-license.php
12 
13   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 
16 **/
17 
18 #ifndef __PEI_BLOCK_IO_H__
19 #define __PEI_BLOCK_IO_H__
20 // {BC5FA650-EDBB-4d0d-B3A3-D98907F847DF}
21 #ifndef ECP_FLAG
22 #define PEI_BLOCK_IO_PPI_GUID \
23   {  \
24     0xbc5fa650, 0xedbb, 0x4d0d, { 0xb3, 0xa3, 0xd9, 0x89, 0x7, 0xf8, 0x47, 0xdf }  \
25   }
26 #endif
27 typedef struct _PEI_BLOCK_IO_PPI  PEI_BLOCK_IO_PPI;
28 
29 
30 /**
31   Reset the Block Device.
32 
33   @param  This                 Indicates a pointer to the calling context.
34   @param  ExtendedVerification Driver may perform diagnostics on reset.
35 
36   @retval EFI_SUCCESS          The device was reset.
37   @retval EFI_DEVICE_ERROR     The device is not functioning properly and could
38                                not be reset.
39 
40 **/
41 typedef
42 EFI_STATUS
43 (EFIAPI *PEI_BLOCK_RESET)(
44   IN PEI_BLOCK_IO_PPI               *This,
45   IN BOOLEAN                        ExtendedVerification
46   );
47 
48 /**
49   Read BufferSize bytes from Lba into Buffer.
50 
51   @param  This       Indicates a pointer to the calling context.
52   @param  MediaId    Id of the media, changes every time the media is replaced.
53   @param  Lba        The starting Logical Block Address to read from
54   @param  BufferSize Size of Buffer, must be a multiple of device block size.
55   @param  Buffer     A pointer to the destination buffer for the data. The caller is
56                      responsible for either having implicit or explicit ownership of the buffer.
57 
58   @retval EFI_SUCCESS           The data was read correctly from the device.
59   @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.
60   @retval EFI_NO_MEDIA          There is no media in the device.
61   @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.
62   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.
63   @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
64                                 or the buffer is not on proper alignment.
65 
66 **/
67 typedef
68 EFI_STATUS
69 (EFIAPI *PEI_BLOCK_READ)(
70   IN  EFI_PEI_SERVICES              **PeiServices,
71   IN PEI_BLOCK_IO_PPI               *This,
72   IN UINT32                         MediaId,
73   IN EFI_LBA                        Lba,
74   IN UINTN                          BufferSize,
75   OUT VOID                          *Buffer
76   );
77 
78 /**
79   Write BufferSize bytes from Lba into Buffer.
80 
81   @param  This       Indicates a pointer to the calling context.
82   @param  MediaId    The media ID that the write request is for.
83   @param  Lba        The starting logical block address to be written. The caller is
84                      responsible for writing to only legitimate locations.
85   @param  BufferSize Size of Buffer, must be a multiple of device block size.
86   @param  Buffer     A pointer to the source buffer for the data.
87 
88   @retval EFI_SUCCESS           The data was written correctly to the device.
89   @retval EFI_WRITE_PROTECTED   The device can not be written to.
90   @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.
91   @retval EFI_NO_MEDIA          There is no media in the device.
92   @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.
93   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.
94   @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
95                                 or the buffer is not on proper alignment.
96 
97 **/
98 typedef
99 EFI_STATUS
100 (EFIAPI *PEI_BLOCK_WRITE)(
101   IN  EFI_PEI_SERVICES              **PeiServices,
102   IN PEI_BLOCK_IO_PPI               *This,
103   IN UINT32                         MediaId,
104   IN EFI_LBA                        Lba,
105   IN UINTN                          BufferSize,
106   IN VOID                           *Buffer
107   );
108 
109 /**
110   Flush the Block Device.
111 
112   @param  This              Indicates a pointer to the calling context.
113 
114   @retval EFI_SUCCESS       All outstanding data was written to the device
115   @retval EFI_DEVICE_ERROR  The device reported an error while writting back the data
116   @retval EFI_NO_MEDIA      There is no media in the device.
117 
118 **/
119 typedef
120 EFI_STATUS
121 (EFIAPI *PEI_BLOCK_FLUSH)(
122   IN  PEI_BLOCK_IO_PPI           *This
123   );
124 
125 /**
126   Block IO read only mode data and updated only via members of BlockIO
127 **/
128 typedef struct {
129   ///
130   /// The curent media Id. If the media changes, this value is changed.
131   ///
132   UINT32  MediaId;
133 
134   ///
135   /// TRUE if the media is removable; otherwise, FALSE.
136   ///
137   BOOLEAN RemovableMedia;
138 
139   ///
140   /// TRUE if there is a media currently present in the device;
141   /// othersise, FALSE. THis field shows the media present status
142   /// as of the most recent ReadBlocks() or WriteBlocks() call.
143   ///
144   BOOLEAN MediaPresent;
145 
146   ///
147   /// TRUE if LBA 0 is the first block of a partition; otherwise
148   /// FALSE. For media with only one partition this would be TRUE.
149   ///
150   BOOLEAN LogicalPartition;
151 
152   ///
153   /// TRUE if the media is marked read-only otherwise, FALSE.
154   /// This field shows the read-only status as of the most recent WriteBlocks () call.
155   ///
156   BOOLEAN ReadOnly;
157 
158   ///
159   /// TRUE if the WriteBlock () function caches write data.
160   ///
161   BOOLEAN WriteCaching;
162 
163   ///
164   /// The intrinsic block size of the device. If the media changes, then
165   /// this field is updated.
166   ///
167   UINT32  BlockSize;
168 
169   ///
170   /// Supplies the alignment requirement for any buffer to read or write block(s).
171   ///
172   UINT32  IoAlign;
173 
174   ///
175   /// The last logical block address on the device.
176   /// If the media changes, then this field is updated.
177   ///
178   EFI_LBA LastBlock;
179 
180   ///
181   /// Only present if EFI_BLOCK_IO_PROTOCOL.Revision is greater than or equal to
182   /// EFI_BLOCK_IO_PROTOCOL_REVISION2. Returns the first LBA is aligned to
183   /// a physical block boundary.
184   ///
185   EFI_LBA LowestAlignedLba;
186 
187   ///
188   /// Only present if EFI_BLOCK_IO_PROTOCOL.Revision is greater than or equal to
189   /// EFI_BLOCK_IO_PROTOCOL_REVISION2. Returns the number of logical blocks
190   /// per physical block.
191   ///
192   UINT32 LogicalBlocksPerPhysicalBlock;
193 
194   ///
195   /// Only present if EFI_BLOCK_IO_PROTOCOL.Revision is greater than or equal to
196   /// EFI_BLOCK_IO_PROTOCOL_REVISION3. Returns the optimal transfer length
197   /// granularity as a number of logical blocks.
198   ///
199   UINT32 OptimalTransferLengthGranularity;
200 #ifdef ECP_FLAG
201 } PEI_BLOCK_IO_MEDIA2;
202 #else
203 } PEI_BLOCK_IO_MEDIA;
204 #endif
205 #define EFI_BLOCK_IO_PROTOCOL_REVISION  0x00010000
206 #define EFI_BLOCK_IO_PROTOCOL_REVISION2 0x00020001
207 #define EFI_BLOCK_IO_PROTOCOL_REVISION3 0x00020031
208 
209 ///
210 /// Revision defined in EFI1.1.
211 ///
212 #define EFI_BLOCK_IO_INTERFACE_REVISION   EFI_BLOCK_IO_PROTOCOL_REVISION
213 
214 ///
215 ///  This protocol provides control over block devices.
216 ///
217 struct _PEI_BLOCK_IO_PPI {
218   ///
219   /// The revision to which the block IO interface adheres. All future
220   /// revisions must be backwards compatible. If a future version is not
221   /// back wards compatible, it is not the same GUID.
222   ///
223   UINT64              Revision;
224   ///
225   /// Pointer to the EFI_BLOCK_IO_MEDIA data for this device.
226   ///
227   PEI_BLOCK_IO_MEDIA  *Media;
228   PEI_BLOCK_RESET     Reset;
229   PEI_BLOCK_READ      ReadBlocks;
230   PEI_BLOCK_WRITE     WriteBlocks;
231   PEI_BLOCK_FLUSH     FlushBlocks;
232 };
233 
234 //extern EFI_GUID gEfiBlockIoProtocolGuid;
235 extern EFI_GUID gPeiBlockIoPpiGuid;
236 #endif
237