]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/XenPvBlkDxe/BlockFront.c
OvmfPkg/MptScsiDxe: Install stubbed EXT_SCSI_PASS_THRU
[mirror_edk2.git] / OvmfPkg / XenPvBlkDxe / BlockFront.c
index c43e7af9a50961a43d282674a10a1fc21a93c04f..122a6baed25a637668a53b7dd029a6ac48a40dc3 100644 (file)
@@ -5,26 +5,7 @@
   Copyright (C) 2014, Citrix Ltd.\r
   Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
 \r
-  Redistribution and use in source and binary forms, with or without\r
-  modification, are permitted provided that the following conditions\r
-  are met:\r
-  1. Redistributions of source code must retain the above copyright\r
-     notice, this list of conditions and the following disclaimer.\r
-  2. Redistributions in binary form must reproduce the above copyright\r
-     notice, this list of conditions and the following disclaimer in the\r
-     documentation and/or other materials provided with the distribution.\r
-\r
-  THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
-  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
-  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
-  ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE\r
-  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
-  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
-  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
-  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
-  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
-  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
-  SUCH DAMAGE.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
 #include <Library/PrintLib.h>\r
@@ -46,7 +27,7 @@
   @param FromBackend  Read frontend or backend value.\r
   @param ValuePtr     Where to put the value.\r
 \r
-  @retval XENSTORE_STATUS_SUCCESS  If succefull, will update ValuePtr.\r
+  @retval XENSTORE_STATUS_SUCCESS  If successful, will update ValuePtr.\r
   @return                          Any other return value indicate the error,\r
                                    ValuePtr is not updated in this case.\r
 **/\r
@@ -142,7 +123,7 @@ XenPvBlkWaitForBackendState (
       Status = XENSTORE_STATUS_FAIL;\r
       break;\r
     }\r
-    DEBUG ((EFI_D_INFO,\r
+    DEBUG ((DEBUG_INFO,\r
             "XenPvBlk: waiting backend state %d, current: %d\n",\r
             ExpectedState, State));\r
     XenBusIo->WaitForWatch (XenBusIo, Dev->StateWatchToken);\r
@@ -169,6 +150,7 @@ XenPvBlockFrontInitialization (
   XEN_BLOCK_FRONT_DEVICE *Dev;\r
   XenbusState State;\r
   UINT64 Value;\r
+  CHAR8 *Params;\r
 \r
   ASSERT (NodeName != NULL);\r
 \r
@@ -186,13 +168,27 @@ XenPvBlockFrontInitialization (
   }\r
   FreePool (DeviceType);\r
 \r
+  if (Dev->MediaInfo.CdRom) {\r
+    Status = XenBusIo->XsBackendRead (XenBusIo, XST_NIL, "params", (VOID**)&Params);\r
+    if (Status != XENSTORE_STATUS_SUCCESS) {\r
+      DEBUG ((DEBUG_ERROR, "%a: Failed to read params (%d)\n", __FUNCTION__, Status));\r
+      goto Error;\r
+    }\r
+    if (AsciiStrLen (Params) == 0 || AsciiStrCmp (Params, "aio:") == 0) {\r
+      FreePool (Params);\r
+      DEBUG ((DEBUG_INFO, "%a: Empty cdrom\n", __FUNCTION__));\r
+      goto Error;\r
+    }\r
+    FreePool (Params);\r
+  }\r
+\r
   Status = XenBusReadUint64 (XenBusIo, "backend-id", FALSE, &Value);\r
   if (Status != XENSTORE_STATUS_SUCCESS || Value > MAX_UINT16) {\r
-    DEBUG ((EFI_D_ERROR, "XenPvBlk: Failed to get backend-id (%d)\n",\r
+    DEBUG ((DEBUG_ERROR, "XenPvBlk: Failed to get backend-id (%d)\n",\r
             Status));\r
     goto Error;\r
   }\r
-  Dev->DomainId = Value;\r
+  Dev->DomainId = (domid_t)Value;\r
   XenBusIo->EventChannelAllocate (XenBusIo, Dev->DomainId, &Dev->EventChannel);\r
 \r
   SharedRing = (blkif_sring_t*) AllocatePages (1);\r
@@ -207,32 +203,32 @@ XenPvBlockFrontInitialization (
 Again:\r
   Status = XenBusIo->XsTransactionStart (XenBusIo, &Transaction);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_WARN, "XenPvBlk: Failed to start transaction, %d\n", Status));\r
+    DEBUG ((DEBUG_WARN, "XenPvBlk: Failed to start transaction, %d\n", Status));\r
     goto Error;\r
   }\r
 \r
   Status = XenBusIo->XsPrintf (XenBusIo, &Transaction, NodeName, "ring-ref", "%d",\r
                                Dev->RingRef);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_ERROR, "XenPvBlk: Failed to write ring-ref.\n"));\r
+    DEBUG ((DEBUG_ERROR, "XenPvBlk: Failed to write ring-ref.\n"));\r
     goto AbortTransaction;\r
   }\r
   Status = XenBusIo->XsPrintf (XenBusIo, &Transaction, NodeName,\r
                                "event-channel", "%d", Dev->EventChannel);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_ERROR, "XenPvBlk: Failed to write event-channel.\n"));\r
+    DEBUG ((DEBUG_ERROR, "XenPvBlk: Failed to write event-channel.\n"));\r
     goto AbortTransaction;\r
   }\r
   Status = XenBusIo->XsPrintf (XenBusIo, &Transaction, NodeName,\r
                                "protocol", "%a", XEN_IO_PROTO_ABI_NATIVE);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_ERROR, "XenPvBlk: Failed to write protocol.\n"));\r
+    DEBUG ((DEBUG_ERROR, "XenPvBlk: Failed to write protocol.\n"));\r
     goto AbortTransaction;\r
   }\r
 \r
   Status = XenBusIo->SetState (XenBusIo, &Transaction, XenbusStateConnected);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_ERROR, "XenPvBlk: Failed to switch state.\n"));\r
+    DEBUG ((DEBUG_ERROR, "XenPvBlk: Failed to switch state.\n"));\r
     goto AbortTransaction;\r
   }\r
 \r
@@ -248,7 +244,7 @@ Again:
   //\r
   Status = XenPvBlkWaitForBackendState (Dev, XenbusStateConnected, &State);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_ERROR,\r
+    DEBUG ((DEBUG_ERROR,\r
             "XenPvBlk: backend for %a/%d not available, rc=%d state=%d\n",\r
             XenBusIo->Type, XenBusIo->DeviceId, Status, State));\r
     goto Error2;\r
@@ -258,7 +254,7 @@ Again:
   if (Status != XENSTORE_STATUS_SUCCESS || Value > MAX_UINT32) {\r
     goto Error2;\r
   }\r
-  Dev->MediaInfo.VDiskInfo = Value;\r
+  Dev->MediaInfo.VDiskInfo = (UINT32)Value;\r
   if (Dev->MediaInfo.VDiskInfo & VDISK_READONLY) {\r
     Dev->MediaInfo.ReadWrite = FALSE;\r
   } else {\r
@@ -274,15 +270,15 @@ Again:
   if (Status != XENSTORE_STATUS_SUCCESS || Value > MAX_UINT32) {\r
     goto Error2;\r
   }\r
-  if (Value % 512 != 0) {\r
+  if ((UINT32)Value % 512 != 0) {\r
     //\r
     // This is not supported by the driver.\r
     //\r
-    DEBUG ((EFI_D_ERROR, "XenPvBlk: Unsupported sector-size value %d, "\r
+    DEBUG ((DEBUG_ERROR, "XenPvBlk: Unsupported sector-size value %Lu, "\r
             "it must be a multiple of 512\n", Value));\r
     goto Error2;\r
   }\r
-  Dev->MediaInfo.SectorSize = Value;\r
+  Dev->MediaInfo.SectorSize = (UINT32)Value;\r
 \r
   // Default value\r
   Value = 0;\r
@@ -302,7 +298,7 @@ Again:
     Dev->MediaInfo.FeatureFlushCache = FALSE;\r
   }\r
 \r
-  DEBUG ((EFI_D_INFO, "XenPvBlk: New disk with %ld sectors of %d bytes\n",\r
+  DEBUG ((DEBUG_INFO, "XenPvBlk: New disk with %ld sectors of %d bytes\n",\r
           Dev->MediaInfo.Sectors, Dev->MediaInfo.SectorSize));\r
 \r
   *DevPtr = Dev;\r
@@ -334,7 +330,7 @@ XenPvBlockFrontShutdown (
 \r
   Status = XenBusIo->SetState (XenBusIo, XST_NIL, XenbusStateClosing);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_ERROR,\r
+    DEBUG ((DEBUG_ERROR,\r
             "XenPvBlk: error while changing state to Closing: %d\n",\r
             Status));\r
     goto Close;\r
@@ -342,7 +338,7 @@ XenPvBlockFrontShutdown (
 \r
   Status = XenPvBlkWaitForBackendState (Dev, XenbusStateClosing, NULL);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_ERROR,\r
+    DEBUG ((DEBUG_ERROR,\r
             "XenPvBlk: error while waiting for closing backend state: %d\n",\r
             Status));\r
     goto Close;\r
@@ -350,7 +346,7 @@ XenPvBlockFrontShutdown (
 \r
   Status = XenBusIo->SetState (XenBusIo, XST_NIL, XenbusStateClosed);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_ERROR,\r
+    DEBUG ((DEBUG_ERROR,\r
             "XenPvBlk: error while changing state to Closed: %d\n",\r
             Status));\r
     goto Close;\r
@@ -358,7 +354,7 @@ XenPvBlockFrontShutdown (
 \r
   Status = XenPvBlkWaitForBackendState (Dev, XenbusStateClosed, NULL);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_ERROR,\r
+    DEBUG ((DEBUG_ERROR,\r
             "XenPvBlk: error while waiting for closed backend state: %d\n",\r
             Status));\r
     goto Close;\r
@@ -366,7 +362,7 @@ XenPvBlockFrontShutdown (
 \r
   Status = XenBusIo->SetState (XenBusIo, XST_NIL, XenbusStateInitialising);\r
   if (Status != XENSTORE_STATUS_SUCCESS) {\r
-    DEBUG ((EFI_D_ERROR,\r
+    DEBUG ((DEBUG_ERROR,\r
             "XenPvBlk: error while changing state to initialising: %d\n",\r
             Status));\r
     goto Close;\r
@@ -375,7 +371,7 @@ XenPvBlockFrontShutdown (
   while (TRUE) {\r
     Status = XenBusReadUint64 (XenBusIo, "state", TRUE, &Value);\r
     if (Status != XENSTORE_STATUS_SUCCESS) {\r
-      DEBUG ((EFI_D_ERROR,\r
+      DEBUG ((DEBUG_ERROR,\r
               "XenPvBlk: error while waiting for new backend state: %d\n",\r
               Status));\r
       goto Close;\r
@@ -383,8 +379,8 @@ XenPvBlockFrontShutdown (
     if (Value <= XenbusStateInitWait || Value >= XenbusStateClosed) {\r
       break;\r
     }\r
-    DEBUG ((EFI_D_INFO,\r
-            "XenPvBlk: waiting backend state %d, current: %d\n",\r
+    DEBUG ((DEBUG_INFO,\r
+            "XenPvBlk: waiting backend state %d, current: %Lu\n",\r
             XenbusStateInitWait, Value));\r
     XenBusIo->WaitForWatch (XenBusIo, Dev->StateWatchToken);\r
   }\r
@@ -439,7 +435,7 @@ XenPvBlockAsyncIo (
 \r
   Start = (UINTN) IoData->Buffer & ~EFI_PAGE_MASK;\r
   End = ((UINTN) IoData->Buffer + IoData->Size + EFI_PAGE_SIZE - 1) & ~EFI_PAGE_MASK;\r
-  IoData->NumRef = NumSegments = (End - Start) / EFI_PAGE_SIZE;\r
+  IoData->NumRef = NumSegments = (INT32)((End - Start) / EFI_PAGE_SIZE);\r
 \r
   ASSERT (NumSegments <= BLKIF_MAX_SEGMENTS_PER_REQUEST);\r
 \r
@@ -448,7 +444,7 @@ XenPvBlockAsyncIo (
   Request = RING_GET_REQUEST (&Dev->Ring, RingIndex);\r
 \r
   Request->operation = IsWrite ? BLKIF_OP_WRITE : BLKIF_OP_READ;\r
-  Request->nr_segments = NumSegments;\r
+  Request->nr_segments = (UINT8)NumSegments;\r
   Request->handle = Dev->DeviceId;\r
   Request->id = (UINTN) IoData;\r
   Request->sector_number = IoData->Sector;\r
@@ -457,9 +453,9 @@ XenPvBlockAsyncIo (
     Request->seg[Index].first_sect = 0;\r
     Request->seg[Index].last_sect = EFI_PAGE_SIZE / 512 - 1;\r
   }\r
-  Request->seg[0].first_sect = ((UINTN) IoData->Buffer & EFI_PAGE_MASK) / 512;\r
+  Request->seg[0].first_sect = (UINT8)(((UINTN) IoData->Buffer & EFI_PAGE_MASK) / 512);\r
   Request->seg[NumSegments - 1].last_sect =\r
-      (((UINTN) IoData->Buffer + IoData->Size - 1) & EFI_PAGE_MASK) / 512;\r
+      (UINT8)((((UINTN) IoData->Buffer + IoData->Size - 1) & EFI_PAGE_MASK) / 512);\r
   for (Index = 0; Index < NumSegments; Index++) {\r
     UINTN Data = Start + Index * EFI_PAGE_SIZE;\r
     XenBusIo->GrantAccess (XenBusIo, Dev->DomainId,\r
@@ -477,7 +473,7 @@ XenPvBlockAsyncIo (
     UINT32 ReturnCode;\r
     ReturnCode = XenBusIo->EventChannelNotify (XenBusIo, Dev->EventChannel);\r
     if (ReturnCode != 0) {\r
-      DEBUG ((EFI_D_ERROR,\r
+      DEBUG ((DEBUG_ERROR,\r
               "XenPvBlk: Unexpected return value from EventChannelNotify: %d\n",\r
               ReturnCode));\r
     }\r
@@ -532,7 +528,7 @@ XenPvBlockPushOperation (
     UINT32 ReturnCode;\r
     ReturnCode = XenBusIo->EventChannelNotify (XenBusIo, Dev->EventChannel);\r
     if (ReturnCode != 0) {\r
-      DEBUG ((EFI_D_ERROR,\r
+      DEBUG ((DEBUG_ERROR,\r
               "XenPvBlk: Unexpected return value from EventChannelNotify: %d\n",\r
               ReturnCode));\r
     }\r
@@ -594,13 +590,13 @@ XenPvBlockAsyncIoPoll (
           INT32 Index;\r
 \r
           if (Status != BLKIF_RSP_OKAY) {\r
-            DEBUG ((EFI_D_ERROR,\r
+            DEBUG ((DEBUG_ERROR,\r
                     "XenPvBlk: "\r
-                    "%a error %d on %a at sector %p, num bytes %p\n",\r
+                    "%a error %d on %a at sector %Lx, num bytes %Lx\n",\r
                     Response->operation == BLKIF_OP_READ ? "read" : "write",\r
                     Status, IoData->Dev->NodeName,\r
-                    IoData->Sector,\r
-                    IoData->Size));\r
+                    (UINT64)IoData->Sector,\r
+                    (UINT64)IoData->Size));\r
           }\r
 \r
           for (Index = 0; Index < IoData->NumRef; Index++) {\r
@@ -612,17 +608,17 @@ XenPvBlockAsyncIoPoll (
 \r
       case BLKIF_OP_WRITE_BARRIER:\r
         if (Status != BLKIF_RSP_OKAY) {\r
-          DEBUG ((EFI_D_ERROR, "XenPvBlk: write barrier error %d\n", Status));\r
+          DEBUG ((DEBUG_ERROR, "XenPvBlk: write barrier error %d\n", Status));\r
         }\r
         break;\r
       case BLKIF_OP_FLUSH_DISKCACHE:\r
         if (Status != BLKIF_RSP_OKAY) {\r
-          DEBUG ((EFI_D_ERROR, "XenPvBlk: flush error %d\n", Status));\r
+          DEBUG ((DEBUG_ERROR, "XenPvBlk: flush error %d\n", Status));\r
         }\r
         break;\r
 \r
       default:\r
-        DEBUG ((EFI_D_ERROR,\r
+        DEBUG ((DEBUG_ERROR,\r
                 "XenPvBlk: unrecognized block operation %d response (status %d)\n",\r
                 Response->operation, Status));\r
         break;\r