diff options
author | Anthony PERARD <anthony.perard@citrix.com> | 2014-10-29 06:52:13 +0000 |
---|---|---|
committer | jljusten <jljusten@Edk2> | 2014-10-29 06:52:13 +0000 |
commit | 5de8a35c62406054f85df87ab67e018a3f4f88c6 (patch) | |
tree | 149ee3baa9a30f9ea7c3402eaaead6ade4eabe4a /OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c | |
parent | 5cce85240450b4f878cc45b2eb16b7b4be74e511 (diff) | |
download | edk2-5de8a35c62406054f85df87ab67e018a3f4f88c6.tar.gz edk2-5de8a35c62406054f85df87ab67e018a3f4f88c6.tar.bz2 edk2-5de8a35c62406054f85df87ab67e018a3f4f88c6.zip |
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
Diffstat (limited to 'OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c')
-rw-r--r-- | OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c index e755a43dd6..caaa9b4ff4 100644 --- a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c +++ b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c @@ -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);
|