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