]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMassImpl.c
index bb292ed3eba8866bfb1f07ef674a362efc05f1a3..8c27e18cdb8754151221d8a00ed943267a9953a2 100644 (file)
@@ -2,13 +2,7 @@
   USB Mass Storage Driver that manages USB Mass Storage Device and produces Block I/O Protocol.\r
 \r
 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -16,7 +10,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #define USB_MASS_TRANSPORT_COUNT    3\r
 //\r
-// Array of USB transport interfaces. \r
+// Array of USB transport interfaces.\r
 //\r
 USB_MASS_TRANSPORT *mUsbMassTransport[USB_MASS_TRANSPORT_COUNT] = {\r
   &mUsbCbi0Transport,\r
@@ -36,7 +30,7 @@ EFI_DRIVER_BINDING_PROTOCOL gUSBMassDriverBinding = {
 /**\r
   Reset the block device.\r
 \r
-  This function implements EFI_BLOCK_IO_PROTOCOL.Reset(). \r
+  This function implements EFI_BLOCK_IO_PROTOCOL.Reset().\r
   It resets the block device hardware.\r
   ExtendedVerification is ignored in this implementation.\r
 \r
@@ -60,7 +54,7 @@ UsbMassReset (
   EFI_STATUS      Status;\r
 \r
   //\r
-  // Raise TPL to TPL_NOTIFY to serialize all its operations\r
+  // Raise TPL to TPL_CALLBACK to serialize all its operations\r
   // to protect shared data structures.\r
   //\r
   OldTpl  = gBS->RaiseTPL (TPL_CALLBACK);\r
@@ -76,7 +70,7 @@ UsbMassReset (
 /**\r
   Reads the requested number of blocks from the device.\r
 \r
-  This function implements EFI_BLOCK_IO_PROTOCOL.ReadBlocks(). \r
+  This function implements EFI_BLOCK_IO_PROTOCOL.ReadBlocks().\r
   It reads the requested number of blocks from the device.\r
   All the blocks are read, or an error is returned.\r
 \r
@@ -114,7 +108,7 @@ UsbMassReadBlocks (
   UINTN               TotalBlock;\r
 \r
   //\r
-  // Raise TPL to TPL_NOTIFY to serialize all its operations\r
+  // Raise TPL to TPL_CALLBACK to serialize all its operations\r
   // to protect shared data structures.\r
   //\r
   OldTpl  = gBS->RaiseTPL (TPL_CALLBACK);\r
@@ -172,9 +166,9 @@ UsbMassReadBlocks (
   }\r
 \r
   if (UsbMass->Cdb16Byte) {\r
-    Status = UsbBootReadBlocks16 (UsbMass, Lba, TotalBlock, Buffer);\r
+    Status = UsbBootReadWriteBlocks16 (UsbMass, FALSE, Lba, TotalBlock, Buffer);\r
   } else {\r
-    Status = UsbBootReadBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer);\r
+    Status = UsbBootReadWriteBlocks (UsbMass, FALSE, (UINT32) Lba, TotalBlock, Buffer);\r
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
@@ -191,7 +185,7 @@ ON_EXIT:
 /**\r
   Writes a specified number of blocks to the device.\r
 \r
-  This function implements EFI_BLOCK_IO_PROTOCOL.WriteBlocks(). \r
+  This function implements EFI_BLOCK_IO_PROTOCOL.WriteBlocks().\r
   It writes a specified number of blocks to the device.\r
   All blocks are written, or an error is returned.\r
 \r
@@ -230,7 +224,7 @@ UsbMassWriteBlocks (
   UINTN               TotalBlock;\r
 \r
   //\r
-  // Raise TPL to TPL_NOTIFY to serialize all its operations\r
+  // Raise TPL to TPL_CALLBACK to serialize all its operations\r
   // to protect shared data structures.\r
   //\r
   OldTpl  = gBS->RaiseTPL (TPL_CALLBACK);\r
@@ -292,10 +286,10 @@ UsbMassWriteBlocks (
   // and clear the status should the write succeed.\r
   //\r
   if (UsbMass->Cdb16Byte) {\r
-    Status = UsbBootWriteBlocks16 (UsbMass, Lba, TotalBlock, Buffer);\r
+    Status = UsbBootReadWriteBlocks16 (UsbMass, TRUE, Lba, TotalBlock, Buffer);\r
   } else {\r
-    Status = UsbBootWriteBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer);\r
-  }  \r
+    Status = UsbBootReadWriteBlocks (UsbMass, TRUE, (UINT32) Lba, TotalBlock, Buffer);\r
+  }\r
 \r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((EFI_D_ERROR, "UsbMassWriteBlocks: UsbBootWriteBlocks (%r) -> Reset\n", Status));\r
@@ -402,7 +396,7 @@ UsbMassInitTransport (
   EFI_USB_INTERFACE_DESCRIPTOR  Interface;\r
   UINT8                         Index;\r
   EFI_STATUS                    Status;\r
\r
+\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiUsbIoProtocolGuid,\r
@@ -415,12 +409,12 @@ UsbMassInitTransport (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  \r
+\r
   Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);\r
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   Status = EFI_UNSUPPORTED;\r
 \r
   //\r
@@ -443,7 +437,7 @@ UsbMassInitTransport (
   }\r
 \r
   //\r
-  // For BOT device, try to get its max LUN. \r
+  // For BOT device, try to get its max LUN.\r
   // If max LUN is 0, then it is a non-lun device.\r
   // Otherwise, it is a multi-lun device.\r
   //\r
@@ -458,7 +452,7 @@ ON_EXIT:
          This->DriverBindingHandle,\r
          Controller\r
          );\r
-  return Status;  \r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -495,14 +489,14 @@ UsbMassInitMultiLun (
   ASSERT (MaxLun > 0);\r
   ReturnStatus = EFI_NOT_FOUND;\r
 \r
-  for (Index = 0; Index <= MaxLun; Index++) { \r
+  for (Index = 0; Index <= MaxLun; Index++) {\r
 \r
     DEBUG ((EFI_D_INFO, "UsbMassInitMultiLun: Start to initialize No.%d logic unit\n", Index));\r
-    \r
+\r
     UsbIo   = NULL;\r
     UsbMass = AllocateZeroPool (sizeof (USB_MASS_DEVICE));\r
     ASSERT (UsbMass != NULL);\r
-      \r
+\r
     UsbMass->Signature            = USB_MASS_SIGNATURE;\r
     UsbMass->UsbIo                = UsbIo;\r
     UsbMass->BlockIo.Media        = &UsbMass->BlockIoMedia;\r
@@ -514,7 +508,7 @@ UsbMassInitMultiLun (
     UsbMass->Transport            = Transport;\r
     UsbMass->Context              = Context;\r
     UsbMass->Lun                  = Index;\r
-    \r
+\r
     //\r
     // Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.\r
     //\r
@@ -531,11 +525,11 @@ UsbMassInitMultiLun (
     LunNode.Header.Type    = MESSAGING_DEVICE_PATH;\r
     LunNode.Header.SubType = MSG_DEVICE_LOGICAL_UNIT_DP;\r
     LunNode.Lun            = UsbMass->Lun;\r
-  \r
+\r
     SetDevicePathNodeLength (&LunNode.Header, sizeof (LunNode));\r
-  \r
+\r
     UsbMass->DevicePath = AppendDevicePathNode (DevicePath, &LunNode.Header);\r
-  \r
+\r
     if (UsbMass->DevicePath == NULL) {\r
       DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: failed to create device logic unit device path\n"));\r
       Status = EFI_OUT_OF_RESOURCES;\r
@@ -558,7 +552,7 @@ UsbMassInitMultiLun (
                     &UsbMass->DiskInfo,\r
                     NULL\r
                     );\r
-    \r
+\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: InstallMultipleProtocolInterfaces (%r)\n", Status));\r
       FreePool (UsbMass->DevicePath);\r
@@ -597,7 +591,7 @@ UsbMassInitMultiLun (
     ReturnStatus = EFI_SUCCESS;\r
     DEBUG ((EFI_D_INFO, "UsbMassInitMultiLun: Success to initialize No.%d logic unit\n", Index));\r
   }\r
-  \r
+\r
   return ReturnStatus;\r
 }\r
 \r
@@ -642,7 +636,7 @@ UsbMassInitNonLun (
     DEBUG ((EFI_D_ERROR, "UsbMassInitNonLun: OpenUsbIoProtocol By Driver (%r)\n", Status));\r
     goto ON_ERROR;\r
   }\r
-  \r
+\r
   UsbMass->Signature            = USB_MASS_SIGNATURE;\r
   UsbMass->Controller           = Controller;\r
   UsbMass->UsbIo                = UsbIo;\r
@@ -654,7 +648,7 @@ UsbMassInitNonLun (
   UsbMass->OpticalStorage       = FALSE;\r
   UsbMass->Transport            = Transport;\r
   UsbMass->Context              = Context;\r
-  \r
+\r
   //\r
   // Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.\r
   //\r
@@ -663,7 +657,7 @@ UsbMassInitNonLun (
     DEBUG ((EFI_D_ERROR, "UsbMassInitNonLun: UsbMassInitMedia (%r)\n", Status));\r
     goto ON_ERROR;\r
   }\r
-    \r
+\r
   InitializeDiskInfo (UsbMass);\r
 \r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
@@ -692,7 +686,7 @@ ON_ERROR:
            Controller\r
            );\r
   }\r
-  return Status;  \r
+  return Status;\r
 }\r
 \r
 \r
@@ -804,7 +798,7 @@ USBMassDriverBindingStart (
   VOID                          *Context;\r
   UINT8                         MaxLun;\r
   EFI_STATUS                    Status;\r
-  EFI_USB_IO_PROTOCOL           *UsbIo; \r
+  EFI_USB_IO_PROTOCOL           *UsbIo;\r
   EFI_TPL                       OldTpl;\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
@@ -824,7 +818,7 @@ USBMassDriverBindingStart (
     // Initialize data for device that does not support multiple LUNSs.\r
     //\r
     Status = UsbMassInitNonLun (This, Controller, Transport, Context);\r
-    if (EFI_ERROR (Status)) { \r
+    if (EFI_ERROR (Status)) {\r
       DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitNonLun (%r)\n", Status));\r
     }\r
   } else {\r
@@ -839,7 +833,7 @@ USBMassDriverBindingStart (
                     Controller,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
                     );\r
-  \r
+\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: OpenDevicePathProtocol By Driver (%r)\n", Status));\r
       goto Exit;\r
@@ -853,7 +847,7 @@ USBMassDriverBindingStart (
                     Controller,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
                     );\r
-  \r
+\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: OpenUsbIoProtocol By Driver (%r)\n", Status));\r
       gBS->CloseProtocol (\r
@@ -941,7 +935,7 @@ USBMassDriverBindingStop (
                     Controller,\r
                     EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                     );\r
-  \r
+\r
     if (EFI_ERROR(Status)) {\r
       //\r
       // This is a 2nd type handle(multi-lun root), it needs to close devicepath\r
@@ -962,13 +956,13 @@ USBMassDriverBindingStop (
       DEBUG ((EFI_D_INFO, "Success to stop multi-lun root handle\n"));\r
       return EFI_SUCCESS;\r
     }\r
-    \r
+\r
     //\r
     // This is a 1st type handle(non-multi-lun), which only needs to uninstall\r
     // Block I/O Protocol, close USB I/O Protocol and free mass device.\r
     //\r
     UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (BlockIo);\r
-  \r
+\r
     //\r
     // Uninstall Block I/O protocol from the device handle,\r
     // then call the transport protocol to stop itself.\r
@@ -984,24 +978,24 @@ USBMassDriverBindingStop (
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
-  \r
+\r
     gBS->CloseProtocol (\r
           Controller,\r
           &gEfiUsbIoProtocolGuid,\r
           This->DriverBindingHandle,\r
           Controller\r
           );\r
-  \r
+\r
     UsbMass->Transport->CleanUp (UsbMass->Context);\r
     FreePool (UsbMass);\r
-    \r
+\r
     DEBUG ((EFI_D_INFO, "Success to stop non-multi-lun root handle\n"));\r
     return EFI_SUCCESS;\r
-  } \r
+  }\r
 \r
   //\r
   // This is a 3rd type handle(multi-lun), which needs uninstall\r
-  // Block I/O Protocol and Device Path Protocol, close USB I/O Protocol and \r
+  // Block I/O Protocol and Device Path Protocol, close USB I/O Protocol and\r
   // free mass device for all children.\r
   //\r
   AllChildrenStopped = TRUE;\r
@@ -1030,7 +1024,7 @@ USBMassDriverBindingStop (
            This->DriverBindingHandle,\r
            ChildHandleBuffer[Index]\r
            );\r
-  \r
+\r
     Status = gBS->UninstallMultipleProtocolInterfaces (\r
                     ChildHandleBuffer[Index],\r
                     &gEfiDevicePathProtocolGuid,\r
@@ -1041,14 +1035,14 @@ USBMassDriverBindingStop (
                     &UsbMass->DiskInfo,\r
                     NULL\r
                     );\r
-    \r
+\r
     if (EFI_ERROR (Status)) {\r
       //\r
       // Fail to uninstall Block I/O Protocol and Device Path Protocol, so re-open USB I/O Protocol by child.\r
       //\r
       AllChildrenStopped = FALSE;\r
       DEBUG ((EFI_D_ERROR, "Fail to stop No.%d multi-lun child handle when uninstalling blockio and devicepath\n", (UINT32)Index));\r
-      \r
+\r
       gBS->OpenProtocol (\r
              Controller,\r
              &gEfiUsbIoProtocolGuid,\r
@@ -1071,7 +1065,7 @@ USBMassDriverBindingStop (
   if (!AllChildrenStopped) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  \r
+\r
   DEBUG ((EFI_D_INFO, "Success to stop all %d multi-lun children handles\n", (UINT32) NumberOfChildren));\r
   return EFI_SUCCESS;\r
 }\r