OvmfPkg/XenPvBlkDxe: Add BlockIo.

Implement the BlockIo protocol.

Change in V4:
- Replace the license by the commonly used file header text.

Change in V3:
- assert(Media->BlockSize % 512 == 0)
- Use Sector instead of Offset to issue IOs.

Change in V2:
- Remove blockIo2 headers.
- Fix few comment.
- file header, copyright
- Rewrite few comment and error messages
- No more callback
- Improving block read/write, increase to the max size in one request
  (instead of only 8pages)
- Fix lastblock when it's a cdrom
- Do uninitialisation when fail to install fail
- few comment
- Licenses

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16274 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Anthony PERARD
2014-10-29 06:52:13 +00:00
committed by jljusten
parent 5cce852404
commit 5de8a35c62
5 changed files with 450 additions and 0 deletions

View File

@@ -261,6 +261,7 @@ XenPvBlkDxeDriverBindingStart (
EFI_STATUS Status;
XENBUS_PROTOCOL *XenBusIo;
XEN_BLOCK_FRONT_DEVICE *Dev;
EFI_BLOCK_IO_MEDIA *Media;
Status = gBS->OpenProtocol (
ControllerHandle,
@@ -279,8 +280,45 @@ XenPvBlkDxeDriverBindingStart (
goto CloseProtocol;
}
CopyMem (&Dev->BlockIo, &gXenPvBlkDxeBlockIo, sizeof (EFI_BLOCK_IO_PROTOCOL));
Media = AllocateCopyPool (sizeof (EFI_BLOCK_IO_MEDIA),
&gXenPvBlkDxeBlockIoMedia);
if (Dev->MediaInfo.VDiskInfo & VDISK_REMOVABLE) {
Media->RemovableMedia = TRUE;
}
Media->MediaPresent = TRUE;
Media->ReadOnly = !Dev->MediaInfo.ReadWrite;
if (Dev->MediaInfo.CdRom) {
//
// If it's a cdrom, the blocksize value need to be 2048 for OVMF to
// recognize it as a cdrom:
// MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
//
Media->BlockSize = 2048;
Media->LastBlock = DivU64x32 (Dev->MediaInfo.Sectors,
Media->BlockSize / Dev->MediaInfo.SectorSize) - 1;
} else {
Media->BlockSize = Dev->MediaInfo.SectorSize;
Media->LastBlock = Dev->MediaInfo.Sectors - 1;
}
ASSERT (Media->BlockSize % 512 == 0);
Dev->BlockIo.Media = Media;
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiBlockIoProtocolGuid, &Dev->BlockIo,
NULL
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "XenPvBlk: install protocol fail: %r\n", Status));
goto UninitBlockFront;
}
return EFI_SUCCESS;
UninitBlockFront:
FreePool (Media);
XenPvBlockFrontShutdown (Dev);
CloseProtocol:
gBS->CloseProtocol (ControllerHandle, &gXenBusProtocolGuid,
This->DriverBindingHandle, ControllerHandle);
@@ -322,6 +360,33 @@ XenPvBlkDxeDriverBindingStop (
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
)
{
EFI_BLOCK_IO_PROTOCOL *BlockIo;
XEN_BLOCK_FRONT_DEVICE *Dev;
EFI_BLOCK_IO_MEDIA *Media;
EFI_STATUS Status;
Status = gBS->OpenProtocol (
ControllerHandle, &gEfiBlockIoProtocolGuid,
(VOID **)&BlockIo,
This->DriverBindingHandle, ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->UninstallProtocolInterface (ControllerHandle,
&gEfiBlockIoProtocolGuid, BlockIo);
if (EFI_ERROR (Status)) {
return Status;
}
Media = BlockIo->Media;
Dev = XEN_BLOCK_FRONT_FROM_BLOCK_IO (BlockIo);
XenPvBlockFrontShutdown (Dev);
FreePool (Media);
gBS->CloseProtocol (ControllerHandle, &gXenBusProtocolGuid,
This->DriverBindingHandle, ControllerHandle);