X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=OvmfPkg%2FXenPvBlkDxe%2FBlockFront.c;h=8dca4c82f08a98888a9d6fb4ee78069b1ca22455;hb=d4534984111328ff839fbf51be2779a98bfefa30;hp=3c039e7add2d1d6f163f69754c9b88b52b217c44;hpb=5cce85240450b4f878cc45b2eb16b7b4be74e511;p=mirror_edk2.git diff --git a/OvmfPkg/XenPvBlkDxe/BlockFront.c b/OvmfPkg/XenPvBlkDxe/BlockFront.c index 3c039e7add..8dca4c82f0 100644 --- a/OvmfPkg/XenPvBlkDxe/BlockFront.c +++ b/OvmfPkg/XenPvBlkDxe/BlockFront.c @@ -3,27 +3,9 @@ Copyright (c) 2007-2008 Samuel Thibault. Copyright (C) 2014, Citrix Ltd. + Copyright (c) 2014, Intel Corporation. All rights reserved.
- Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - SUCH DAMAGE. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include @@ -34,11 +16,6 @@ #include #include -// -// Header used for UINT32_MAX and UINT16_MAX -// -#include "inttypes.h" - /** Helper to read an integer from XenStore. @@ -166,13 +143,14 @@ XenPvBlockFrontInitialization ( OUT XEN_BLOCK_FRONT_DEVICE **DevPtr ) { - XENSTORE_TRANSACTION xbt; + XENSTORE_TRANSACTION Transaction; CHAR8 *DeviceType; blkif_sring_t *SharedRing; XENSTORE_STATUS Status; XEN_BLOCK_FRONT_DEVICE *Dev; XenbusState State; UINT64 Value; + CHAR8 *Params; ASSERT (NodeName != NULL); @@ -190,13 +168,27 @@ XenPvBlockFrontInitialization ( } FreePool (DeviceType); + if (Dev->MediaInfo.CdRom) { + Status = XenBusIo->XsBackendRead (XenBusIo, XST_NIL, "params", (VOID**)&Params); + if (Status != XENSTORE_STATUS_SUCCESS) { + DEBUG ((EFI_D_ERROR, "%a: Failed to read params (%d)\n", __FUNCTION__, Status)); + goto Error; + } + if (AsciiStrLen (Params) == 0 || AsciiStrCmp (Params, "aio:") == 0) { + FreePool (Params); + DEBUG ((EFI_D_INFO, "%a: Empty cdrom\n", __FUNCTION__)); + goto Error; + } + FreePool (Params); + } + Status = XenBusReadUint64 (XenBusIo, "backend-id", FALSE, &Value); - if (Status != XENSTORE_STATUS_SUCCESS || Value > UINT16_MAX) { + if (Status != XENSTORE_STATUS_SUCCESS || Value > MAX_UINT16) { DEBUG ((EFI_D_ERROR, "XenPvBlk: Failed to get backend-id (%d)\n", Status)); goto Error; } - Dev->DomainId = Value; + Dev->DomainId = (domid_t)Value; XenBusIo->EventChannelAllocate (XenBusIo, Dev->DomainId, &Dev->EventChannel); SharedRing = (blkif_sring_t*) AllocatePages (1); @@ -209,38 +201,38 @@ XenPvBlockFrontInitialization ( &Dev->RingRef); Again: - Status = XenBusIo->XsTransactionStart (XenBusIo, &xbt); + Status = XenBusIo->XsTransactionStart (XenBusIo, &Transaction); if (Status != XENSTORE_STATUS_SUCCESS) { DEBUG ((EFI_D_WARN, "XenPvBlk: Failed to start transaction, %d\n", Status)); goto Error; } - Status = XenBusIo->XsPrintf (XenBusIo, xbt, NodeName, "ring-ref", "%d", + Status = XenBusIo->XsPrintf (XenBusIo, &Transaction, NodeName, "ring-ref", "%d", Dev->RingRef); if (Status != XENSTORE_STATUS_SUCCESS) { DEBUG ((EFI_D_ERROR, "XenPvBlk: Failed to write ring-ref.\n")); goto AbortTransaction; } - Status = XenBusIo->XsPrintf (XenBusIo, xbt, NodeName, + Status = XenBusIo->XsPrintf (XenBusIo, &Transaction, NodeName, "event-channel", "%d", Dev->EventChannel); if (Status != XENSTORE_STATUS_SUCCESS) { DEBUG ((EFI_D_ERROR, "XenPvBlk: Failed to write event-channel.\n")); goto AbortTransaction; } - Status = XenBusIo->XsPrintf (XenBusIo, xbt, NodeName, + Status = XenBusIo->XsPrintf (XenBusIo, &Transaction, NodeName, "protocol", "%a", XEN_IO_PROTO_ABI_NATIVE); if (Status != XENSTORE_STATUS_SUCCESS) { DEBUG ((EFI_D_ERROR, "XenPvBlk: Failed to write protocol.\n")); goto AbortTransaction; } - Status = XenBusIo->SetState (XenBusIo, xbt, XenbusStateConnected); + Status = XenBusIo->SetState (XenBusIo, &Transaction, XenbusStateConnected); if (Status != XENSTORE_STATUS_SUCCESS) { DEBUG ((EFI_D_ERROR, "XenPvBlk: Failed to switch state.\n")); goto AbortTransaction; } - Status = XenBusIo->XsTransactionEnd (XenBusIo, xbt, FALSE); + Status = XenBusIo->XsTransactionEnd (XenBusIo, &Transaction, FALSE); if (Status == XENSTORE_STATUS_EAGAIN) { goto Again; } @@ -259,10 +251,10 @@ Again: } Status = XenBusReadUint64 (XenBusIo, "info", TRUE, &Value); - if (Status != XENSTORE_STATUS_SUCCESS || Value > UINT32_MAX) { + if (Status != XENSTORE_STATUS_SUCCESS || Value > MAX_UINT32) { goto Error2; } - Dev->MediaInfo.VDiskInfo = Value; + Dev->MediaInfo.VDiskInfo = (UINT32)Value; if (Dev->MediaInfo.VDiskInfo & VDISK_READONLY) { Dev->MediaInfo.ReadWrite = FALSE; } else { @@ -275,18 +267,18 @@ Again: } Status = XenBusReadUint64 (XenBusIo, "sector-size", TRUE, &Value); - if (Status != XENSTORE_STATUS_SUCCESS || Value > UINT32_MAX) { + if (Status != XENSTORE_STATUS_SUCCESS || Value > MAX_UINT32) { goto Error2; } - if (Value % 512 != 0) { + if ((UINT32)Value % 512 != 0) { // // This is not supported by the driver. // - DEBUG ((EFI_D_ERROR, "XenPvBlk: Unsupported sector-size value %d, " + DEBUG ((EFI_D_ERROR, "XenPvBlk: Unsupported sector-size value %Lu, " "it must be a multiple of 512\n", Value)); goto Error2; } - Dev->MediaInfo.SectorSize = Value; + Dev->MediaInfo.SectorSize = (UINT32)Value; // Default value Value = 0; @@ -319,7 +311,7 @@ Error2: XenBusIo->XsRemove (XenBusIo, XST_NIL, "protocol"); goto Error; AbortTransaction: - XenBusIo->XsTransactionEnd (XenBusIo, xbt, TRUE); + XenBusIo->XsTransactionEnd (XenBusIo, &Transaction, TRUE); Error: XenPvBlockFree (Dev); return EFI_DEVICE_ERROR; @@ -388,7 +380,7 @@ XenPvBlockFrontShutdown ( break; } DEBUG ((EFI_D_INFO, - "XenPvBlk: waiting backend state %d, current: %d\n", + "XenPvBlk: waiting backend state %d, current: %Lu\n", XenbusStateInitWait, Value)); XenBusIo->WaitForWatch (XenBusIo, Dev->StateWatchToken); } @@ -443,7 +435,7 @@ XenPvBlockAsyncIo ( Start = (UINTN) IoData->Buffer & ~EFI_PAGE_MASK; End = ((UINTN) IoData->Buffer + IoData->Size + EFI_PAGE_SIZE - 1) & ~EFI_PAGE_MASK; - IoData->NumRef = NumSegments = (End - Start) / EFI_PAGE_SIZE; + IoData->NumRef = NumSegments = (INT32)((End - Start) / EFI_PAGE_SIZE); ASSERT (NumSegments <= BLKIF_MAX_SEGMENTS_PER_REQUEST); @@ -452,7 +444,7 @@ XenPvBlockAsyncIo ( Request = RING_GET_REQUEST (&Dev->Ring, RingIndex); Request->operation = IsWrite ? BLKIF_OP_WRITE : BLKIF_OP_READ; - Request->nr_segments = NumSegments; + Request->nr_segments = (UINT8)NumSegments; Request->handle = Dev->DeviceId; Request->id = (UINTN) IoData; Request->sector_number = IoData->Sector; @@ -461,9 +453,9 @@ XenPvBlockAsyncIo ( Request->seg[Index].first_sect = 0; Request->seg[Index].last_sect = EFI_PAGE_SIZE / 512 - 1; } - Request->seg[0].first_sect = ((UINTN) IoData->Buffer & EFI_PAGE_MASK) / 512; + Request->seg[0].first_sect = (UINT8)(((UINTN) IoData->Buffer & EFI_PAGE_MASK) / 512); Request->seg[NumSegments - 1].last_sect = - (((UINTN) IoData->Buffer + IoData->Size - 1) & EFI_PAGE_MASK) / 512; + (UINT8)((((UINTN) IoData->Buffer + IoData->Size - 1) & EFI_PAGE_MASK) / 512); for (Index = 0; Index < NumSegments; Index++) { UINTN Data = Start + Index * EFI_PAGE_SIZE; XenBusIo->GrantAccess (XenBusIo, Dev->DomainId, @@ -600,11 +592,11 @@ XenPvBlockAsyncIoPoll ( if (Status != BLKIF_RSP_OKAY) { DEBUG ((EFI_D_ERROR, "XenPvBlk: " - "%a error %d on %a at sector %p, num bytes %p\n", + "%a error %d on %a at sector %Lx, num bytes %Lx\n", Response->operation == BLKIF_OP_READ ? "read" : "write", Status, IoData->Dev->NodeName, - IoData->Sector, - IoData->Size)); + (UINT64)IoData->Sector, + (UINT64)IoData->Size)); } for (Index = 0; Index < IoData->NumRef; Index++) {