X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=OvmfPkg%2FXenPvBlkDxe%2FXenPvBlkDxe.c;h=dfc40bffaada14f97bfb870e6c8603d6668a67c1;hp=1440e1d23b66fdebdd82483bb0281be8cc99b2c2;hb=ac0a286f4d747a4c6c603a7b225917293cbe1e9f;hpb=d1050b9dff1cace252aff86630bfdb59dff5f507 diff --git a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c index 1440e1d23b..dfc40bffaa 100644 --- a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c +++ b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c @@ -16,11 +16,10 @@ #include "BlockFront.h" - /// /// Driver Binding Protocol instance /// -EFI_DRIVER_BINDING_PROTOCOL gXenPvBlkDxeDriverBinding = { +EFI_DRIVER_BINDING_PROTOCOL gXenPvBlkDxeDriverBinding = { XenPvBlkDxeDriverBindingSupported, XenPvBlkDxeDriverBindingStart, XenPvBlkDxeDriverBindingStop, @@ -29,7 +28,6 @@ EFI_DRIVER_BINDING_PROTOCOL gXenPvBlkDxeDriverBinding = { NULL }; - /** Unloads an image. @@ -51,7 +49,6 @@ XenPvBlkDxeUnload ( UINTN HandleCount; UINTN Index; - // // Retrieve array of all handles in the handle database // @@ -78,15 +75,17 @@ XenPvBlkDxeUnload ( // FreePool (HandleBuffer); - // // Uninstall protocols installed in the driver entry point // Status = gBS->UninstallMultipleProtocolInterfaces ( ImageHandle, - &gEfiDriverBindingProtocolGuid, &gXenPvBlkDxeDriverBinding, - &gEfiComponentNameProtocolGuid, &gXenPvBlkDxeComponentName, - &gEfiComponentName2ProtocolGuid, &gXenPvBlkDxeComponentName2, + &gEfiDriverBindingProtocolGuid, + &gXenPvBlkDxeDriverBinding, + &gEfiComponentNameProtocolGuid, + &gXenPvBlkDxeComponentName, + &gEfiComponentName2ProtocolGuid, + &gXenPvBlkDxeComponentName2, NULL ); if (EFI_ERROR (Status)) { @@ -132,7 +131,6 @@ XenPvBlkDxeDriverEntryPoint ( return Status; } - /** Tests to see if this driver supports a given controller. If a child device is provided, it further tests to see if this driver supports creating a handle for the specified child device. @@ -183,28 +181,33 @@ XenPvBlkDxeDriverBindingSupported ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { - EFI_STATUS Status; - XENBUS_PROTOCOL *XenBusIo; + EFI_STATUS Status; + XENBUS_PROTOCOL *XenBusIo; Status = gBS->OpenProtocol ( - ControllerHandle, - &gXenBusProtocolGuid, - (VOID **)&XenBusIo, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); + ControllerHandle, + &gXenBusProtocolGuid, + (VOID **)&XenBusIo, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); if (EFI_ERROR (Status)) { return Status; } + if (AsciiStrCmp (XenBusIo->Type, "vbd") == 0) { Status = EFI_SUCCESS; } else { Status = EFI_UNSUPPORTED; } - gBS->CloseProtocol (ControllerHandle, &gXenBusProtocolGuid, - This->DriverBindingHandle, ControllerHandle); + gBS->CloseProtocol ( + ControllerHandle, + &gXenBusProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); return Status; } @@ -252,19 +255,19 @@ XenPvBlkDxeDriverBindingStart ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { - EFI_STATUS Status; - XENBUS_PROTOCOL *XenBusIo; - XEN_BLOCK_FRONT_DEVICE *Dev; - EFI_BLOCK_IO_MEDIA *Media; + EFI_STATUS Status; + XENBUS_PROTOCOL *XenBusIo; + XEN_BLOCK_FRONT_DEVICE *Dev; + EFI_BLOCK_IO_MEDIA *Media; Status = gBS->OpenProtocol ( - ControllerHandle, - &gXenBusProtocolGuid, - (VOID **)&XenBusIo, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); + ControllerHandle, + &gXenBusProtocolGuid, + (VOID **)&XenBusIo, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); if (EFI_ERROR (Status)) { return Status; } @@ -275,13 +278,16 @@ XenPvBlkDxeDriverBindingStart ( } CopyMem (&Dev->BlockIo, &gXenPvBlkDxeBlockIo, sizeof (EFI_BLOCK_IO_PROTOCOL)); - Media = AllocateCopyPool (sizeof (EFI_BLOCK_IO_MEDIA), - &gXenPvBlkDxeBlockIoMedia); + 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; + Media->ReadOnly = !Dev->MediaInfo.ReadWrite; if (Dev->MediaInfo.CdRom) { // // If it's a cdrom, the blocksize value need to be 2048 for OVMF to @@ -289,20 +295,24 @@ XenPvBlkDxeDriverBindingStart ( // MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c // Media->BlockSize = 2048; - Media->LastBlock = DivU64x32 (Dev->MediaInfo.Sectors, - Media->BlockSize / Dev->MediaInfo.SectorSize) - 1; + 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 - ); + &ControllerHandle, + &gEfiBlockIoProtocolGuid, + &Dev->BlockIo, + NULL + ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "XenPvBlk: install protocol fail: %r\n", Status)); goto UninitBlockFront; @@ -314,8 +324,12 @@ UninitBlockFront: FreePool (Media); XenPvBlockFrontShutdown (Dev); CloseProtocol: - gBS->CloseProtocol (ControllerHandle, &gXenBusProtocolGuid, - This->DriverBindingHandle, ControllerHandle); + gBS->CloseProtocol ( + ControllerHandle, + &gXenBusProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); return Status; } @@ -354,35 +368,44 @@ XenPvBlkDxeDriverBindingStop ( IN EFI_HANDLE *ChildHandleBuffer OPTIONAL ) { - EFI_BLOCK_IO_PROTOCOL *BlockIo; - XEN_BLOCK_FRONT_DEVICE *Dev; - EFI_BLOCK_IO_MEDIA *Media; - EFI_STATUS Status; + EFI_BLOCK_IO_PROTOCOL *BlockIo; + XEN_BLOCK_FRONT_DEVICE *Dev; + EFI_BLOCK_IO_MEDIA *Media; + EFI_STATUS Status; Status = gBS->OpenProtocol ( - ControllerHandle, &gEfiBlockIoProtocolGuid, + ControllerHandle, + &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo, - This->DriverBindingHandle, ControllerHandle, + This->DriverBindingHandle, + ControllerHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } - Status = gBS->UninstallProtocolInterface (ControllerHandle, - &gEfiBlockIoProtocolGuid, BlockIo); + Status = gBS->UninstallProtocolInterface ( + ControllerHandle, + &gEfiBlockIoProtocolGuid, + BlockIo + ); if (EFI_ERROR (Status)) { return Status; } Media = BlockIo->Media; - Dev = XEN_BLOCK_FRONT_FROM_BLOCK_IO (BlockIo); + Dev = XEN_BLOCK_FRONT_FROM_BLOCK_IO (BlockIo); XenPvBlockFrontShutdown (Dev); FreePool (Media); - gBS->CloseProtocol (ControllerHandle, &gXenBusProtocolGuid, - This->DriverBindingHandle, ControllerHandle); + gBS->CloseProtocol ( + ControllerHandle, + &gXenBusProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); return EFI_SUCCESS; }