您的位置:首页 > 产品设计 > UI/UE

BIOS/UEFI基础——块设备访问

2016-09-14 22:28 417 查看
UEFI下的基本块设备访问接口是以下的几个:gEfiBlockIoProtocolGuid;
///
/// This protocol provides control over block devices.
///
struct _EFI_BLOCK_IO_PROTOCOL {
///
/// The revision to which the block IO interface adheres. All future
/// revisions must be backwards compatible. If a future version is not
/// back wards compatible, it is not the same GUID.
///
UINT64 Revision;
///
/// Pointer to the EFI_BLOCK_IO_MEDIA data for this device.
///
EFI_BLOCK_IO_MEDIA *Media;

EFI_BLOCK_RESET Reset;
EFI_BLOCK_READ ReadBlocks;
EFI_BLOCK_WRITE WriteBlocks;
EFI_BLOCK_FLUSH FlushBlocks;

};以及gEfiDiskIoProtocolGuid;
///
/// This protocol is used to abstract Block I/O interfaces.
///
struct _EFI_DISK_IO_PROTOCOL {
///
/// The revision to which the disk I/O interface adheres. All future
/// revisions must be backwards compatible. If a future version is not
/// backwards compatible, it is not the same GUID.
///
UINT64 Revision;
EFI_DISK_READ ReadDisk;
EFI_DISK_WRITE WriteDisk;
};
其中DiskIoProtocol对应的是一个UEFI Driver  Model。它依赖于BlockIoProtocol:EFI_STATUS
EFIAPI
DiskIoDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlockIo;

//
// Open the IO Abstraction(s) needed to perform the supported test.
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiBlockIoProtocolGuid,
(VOID **) &BlockIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
一般我们使用的时候会用DiskIoProtocol来读写块设备,而不是使用BlockIoProtocol,不过BlockIoProtocol并不是没有用,因为在DiskIoProtocol的读写接口中都需要使用到BlockIoProtocol的参数:
/**
Read BufferSize bytes from Offset into Buffer.

@param  This                  Protocol instance pointer.
@param  MediaId               Id of the media, changes every time the media is replaced.
@param  Offset                The starting byte offset to read from
@param  BufferSize            Size of Buffer
@param  Buffer                Buffer containing read data

@retval EFI_SUCCESS           The data was read correctly from the device.
@retval EFI_DEVICE_ERROR      The device reported an error while performing the read.
@retval EFI_NO_MEDIA          There is no media in the device.
@retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.
@retval EFI_INVALID_PARAMETER The read request contains device addresses that are not
valid for the device.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_DISK_READ)(
IN EFI_DISK_IO_PROTOCOL         *This,
IN UINT32                       MediaId,
IN UINT64                       Offset,
IN UINTN                        BufferSize,
OUT VOID                        *Buffer
);
其中的MediaId就是在BlockIoProtocol中定义的EFI_BLOCK_IO_MEDIA结构体中:
/**
Block IO read only mode data and updated only via members of BlockIO
**/
typedef struct {
///
/// The curent media Id. If the media changes, this value is changed.
///
UINT32  MediaId;
另外,它们都对应有一个2版本,算是加强版,这里不具体说明。
无论是BlockIoProtocol还是DiskIoProtocol,其实都只是UEFI层的抽象,具体的IO实现还需要块设备驱动自己做,完了之后就会安装BlockIoProtocol。
之后才有DiskIoProtocol的进一步封装。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uefi