]> git.proxmox.com Git - mirror_edk2.git/commitdiff
[Description]:
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 27 Jun 2008 08:09:00 +0000 (08:09 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 27 Jun 2008 08:09:00 +0000 (08:09 +0000)
 UsbMassStorage driver need support multi-lun feature.
[Impaction]:
 UsbMassStorageDxe.
[Reference Info]:
 EDK tracker 1143 - UsbMassStorage driver need support multi-lun feature.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5375 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMass.h
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.h
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf

index fe3f8b9e68100ccd9e1bd26d4248f025f95efdea..8908a9dab82ac5d5df08df5fee9dc6f3805f8d19 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. 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
@@ -36,6 +36,7 @@ Revision History
 \r
 #include <Protocol/BlockIo.h>\r
 #include <Protocol/UsbIo.h>\r
+#include <Protocol/DevicePath.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
@@ -43,6 +44,7 @@ Revision History
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
+#include <Library/DevicePathLib.h>\r
 \r
 #define USB_IS_IN_ENDPOINT(EndPointAddr)      (((EndPointAddr) & 0x80) == 0x80)\r
 #define USB_IS_OUT_ENDPOINT(EndPointAddr)     (((EndPointAddr) & 0x80) == 0)\r
@@ -85,7 +87,6 @@ typedef
 EFI_STATUS\r
 (*USB_MASS_INIT_TRANSPORT) (\r
   IN  EFI_USB_IO_PROTOCOL     *Usb,\r
-  IN  EFI_HANDLE              Controller,\r
   OUT VOID                    **Context    OPTIONAL\r
   );\r
 \r
@@ -98,6 +99,7 @@ EFI_STATUS
   IN  EFI_USB_DATA_DIRECTION  DataDir,\r
   IN  VOID                    *Data,\r
   IN  UINT32                  DataLen,\r
+  IN  UINT8                   Lun,\r
   IN  UINT32                  Timeout,\r
   OUT UINT32                  *CmdStatus\r
   );\r
@@ -109,6 +111,13 @@ EFI_STATUS
   IN  BOOLEAN                 ExtendedVerification\r
   );\r
 \r
+typedef\r
+EFI_STATUS\r
+(*USB_MASS_GET_MAX_LUN) (\r
+  IN  VOID                    *Context,\r
+  IN  UINT8                   *MaxLun\r
+  );\r
+\r
 typedef\r
 EFI_STATUS\r
 (*USB_MASS_FINI) (\r
@@ -128,6 +137,7 @@ typedef struct {
   USB_MASS_INIT_TRANSPORT Init;        // Initialize the mass storage transport protocol\r
   USB_MASS_EXEC_COMMAND   ExecCommand; // Transport command to the device then get result\r
   USB_MASS_RESET          Reset;       // Reset the device\r
+  USB_MASS_GET_MAX_LUN    GetMaxLun;   // Get max lun, only for bot\r
   USB_MASS_FINI           Fini;        // Clean up the resources.\r
 } USB_MASS_TRANSPORT;\r
 \r
index 8dd7ada7d648503a38b6faefd59778cdca54abf8..9b2ba5ab390d5567bc15ba000877eafbea47e3a0 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. 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
@@ -163,6 +163,7 @@ UsbBootRequestSense (
                         EfiUsbDataIn,\r
                         &SenseData,\r
                         sizeof (USB_BOOT_REQUEST_SENSE_DATA),\r
+                        UsbMass->Lun,\r
                         USB_BOOT_GENERAL_CMD_TIMEOUT,\r
                         &CmdResult\r
                         );\r
@@ -280,6 +281,7 @@ UsbBootExecCmd (
                            DataDir,\r
                            Data,\r
                            DataLen,\r
+                           UsbMass->Lun,\r
                            Timeout,\r
                            &CmdResult\r
                            );\r
index 3277fa993221e5a29f8b063f37afba83af168435..c6168ec87d68557a37ae58808e9e5717c12066c3 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. 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
@@ -39,7 +39,6 @@ UsbBotResetDevice (
   in the Context if Context isn't NULL.\r
 \r
   @param  UsbIo                 The USB IO protocol to use\r
-  @param  Controller            The controller to init\r
   @param  Context               The variable to save the context to\r
 \r
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate memory\r
@@ -51,7 +50,6 @@ STATIC
 EFI_STATUS\r
 UsbBotInit (\r
   IN  EFI_USB_IO_PROTOCOL       * UsbIo,\r
-  IN  EFI_HANDLE                Controller,\r
   OUT VOID                      **Context OPTIONAL\r
   )\r
 {\r
@@ -149,6 +147,7 @@ ON_ERROR:
   @param  CmdLen                the length of the command\r
   @param  DataDir               The direction of the data\r
   @param  TransLen              The expected length of the data\r
+  @param  Lun                   The number of logic unit\r
 \r
   @retval EFI_NOT_READY         The device return NAK to the transfer\r
   @retval EFI_SUCCESS           The command is sent to the device.\r
@@ -162,7 +161,8 @@ UsbBotSendCommand (
   IN UINT8                    *Cmd,\r
   IN UINT8                    CmdLen,\r
   IN EFI_USB_DATA_DIRECTION   DataDir,\r
-  IN UINT32                   TransLen\r
+  IN UINT32                   TransLen,\r
+  IN UINT8                    Lun\r
   )\r
 {\r
   USB_BOT_CBW               Cbw;\r
@@ -180,7 +180,7 @@ UsbBotSendCommand (
   Cbw.Tag       = UsbBot->CbwTag;\r
   Cbw.DataLen   = TransLen;\r
   Cbw.Flag      = (UINT8) ((DataDir == EfiUsbDataIn) ? 0x80 : 0);\r
-  Cbw.Lun       = 0;\r
+  Cbw.Lun       = Lun;\r
   Cbw.CmdLen    = CmdLen;\r
 \r
   ZeroMem (Cbw.CmdBlock, USB_BOT_MAX_CMDLEN);\r
@@ -389,6 +389,7 @@ UsbBotGetStatus (
   @param  DataDir               The direction of the data transfer\r
   @param  Data                  The buffer to hold data\r
   @param  DataLen               The length of the data\r
+  @param  Lun                   The number of logic unit\r
   @param  Timeout               The time to wait command\r
   @param  CmdStatus             The result of high level command execution\r
 \r
@@ -405,6 +406,7 @@ UsbBotExecCommand (
   IN  EFI_USB_DATA_DIRECTION  DataDir,\r
   IN  VOID                    *Data,\r
   IN  UINT32                  DataLen,\r
+  IN  UINT8                   Lun,\r
   IN  UINT32                  Timeout,\r
   OUT UINT32                  *CmdStatus\r
   )\r
@@ -421,7 +423,7 @@ UsbBotExecCommand (
   // Send the command to the device. Return immediately if device\r
   // rejects the command.\r
   //\r
-  Status = UsbBotSendCommand (UsbBot, Cmd, CmdLen, DataDir, DataLen);\r
+  Status = UsbBotSendCommand (UsbBot, Cmd, CmdLen, DataDir, DataLen, Lun);\r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((EFI_D_ERROR, "UsbBotExecCommand: UsbBotSendCommand (%r)\n", Status));\r
     return Status;\r
@@ -488,10 +490,10 @@ UsbBotResetDevice (
   }\r
 \r
   //\r
-  // Issue a class specific "Bulk-Only Mass Storage Reset reqest.\r
+  // Issue a class specific Bulk-Only Mass Storage Reset reqest.\r
   // See the spec section 3.1\r
   //\r
-  Request.RequestType = 0x21;\r
+  Request.RequestType = 0x21; // Class, Interface, Host to Device\r
   Request.Request     = USB_BOT_RESET_REQUEST;\r
   Request.Value       = 0;\r
   Request.Index       = UsbBot->Interface.InterfaceNumber;\r
@@ -528,6 +530,86 @@ UsbBotResetDevice (
   return Status;\r
 }\r
 \r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Reset the mass storage device by BOT protocol\r
+\r
+Arguments:\r
+\r
+  Context - The context of the BOT protocol, that is, USB_BOT_PROTOCOL\r
+  MaxLun  - Return pointer to the max number of lun. Maxlun=1 means lun0 and \r
+            lun1 in all.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - The device is reset\r
+  Others      - Failed to reset the device.\r
+\r
+--*/\r
+STATIC\r
+EFI_STATUS\r
+UsbBotGetMaxLun (\r
+  IN  VOID                    *Context,\r
+  IN  UINT8                   *MaxLun\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Reset the mass storage device by BOT protocol\r
+\r
+Arguments:\r
+\r
+  Context - The context of the BOT protocol, that is, USB_BOT_PROTOCOL\r
+  MaxLun  - Return pointer to the max number of lun. Maxlun=1 means lun0 and \r
+            lun1 in all.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - The device is reset\r
+  Others      - Failed to reset the device.\r
+\r
+--*/\r
+{\r
+  USB_BOT_PROTOCOL        *UsbBot;\r
+  EFI_USB_DEVICE_REQUEST  Request;\r
+  EFI_STATUS              Status;\r
+  UINT32                  Result;\r
+  UINT32                  Timeout;\r
+\r
+  ASSERT (Context);\r
+  \r
+  UsbBot = (USB_BOT_PROTOCOL *) Context;\r
+\r
+  //\r
+  // Issue a class specific Bulk-Only Mass Storage get max lun reqest.\r
+  // See the spec section 3.2\r
+  //\r
+  Request.RequestType = 0xA1; // Class, Interface, Device to Host\r
+  Request.Request     = USB_BOT_GETLUN_REQUEST;\r
+  Request.Value       = 0;\r
+  Request.Index       = UsbBot->Interface.InterfaceNumber;\r
+  Request.Length      = 1;\r
+  Timeout             = USB_BOT_RESET_DEVICE_TIMEOUT / USB_MASS_1_MILLISECOND;\r
+\r
+  Status = UsbBot->UsbIo->UsbControlTransfer (\r
+                            UsbBot->UsbIo,\r
+                            &Request,\r
+                            EfiUsbDataIn,\r
+                            Timeout,\r
+                            (VOID *)MaxLun,\r
+                            1,\r
+                            &Result\r
+                            );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "UsbBotGetMaxLun: (%r)\n", Status));\r
+  }\r
+\r
+  return Status;\r
+}\r
 \r
 /**\r
   Clean up the resource used by this BOT protocol\r
@@ -554,5 +636,7 @@ mUsbBotTransport = {
   UsbBotInit,\r
   UsbBotExecCommand,\r
   UsbBotResetDevice,\r
+  UsbBotGetMaxLun,\r
   UsbBotFini\r
 };\r
+\r
index a46a9a3843312df355b612437bc66b3761e983dd..151b59e39709f2e43a0105913a4f10d373e7bc0b 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. 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
@@ -40,7 +40,6 @@ UsbCbiResetDevice (
   If Context isn't NULL, it will save its context in it.\r
 \r
   @param  UsbIo                 The USB IO to use\r
-  @param  Controller            The device controller\r
   @param  Context               The variable to save context in\r
 \r
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate memory\r
@@ -52,7 +51,6 @@ STATIC
 EFI_STATUS\r
 UsbCbiInit (\r
   IN  EFI_USB_IO_PROTOCOL   *UsbIo,\r
-  IN  EFI_HANDLE            Controller,\r
   OUT VOID                  **Context       OPTIONAL\r
   )\r
 {\r
@@ -413,6 +411,7 @@ UsbCbiGetStatus (
   @param  DataDir               The direction of data transfer\r
   @param  Data                  The buffer to hold the data\r
   @param  DataLen               The length of the buffer\r
+  @param  Lun                   Should be 0, this field for bot only\r
   @param  Timeout               The time to wait\r
   @param  CmdStatus             The result of the command execution\r
 \r
@@ -429,6 +428,7 @@ UsbCbiExecCommand (
   IN  EFI_USB_DATA_DIRECTION  DataDir,\r
   IN  VOID                    *Data,\r
   IN  UINT32                  DataLen,\r
+  IN  UINT8                   Lun,\r
   IN  UINT32                  Timeout,\r
   OUT UINT32                  *CmdStatus\r
   )\r
@@ -603,6 +603,7 @@ mUsbCbi0Transport = {
   UsbCbiInit,\r
   UsbCbiExecCommand,\r
   UsbCbiResetDevice,\r
+  NULL,\r
   UsbCbiFini\r
 };\r
 \r
@@ -612,5 +613,6 @@ mUsbCbi1Transport = {
   UsbCbiInit,\r
   UsbCbiExecCommand,\r
   UsbCbiResetDevice,\r
+  NULL,\r
   UsbCbiFini\r
 };\r
index 71ccfa9d10c2b34008af2c262b0292a42d164042..e556c4da61f5b2c75ebe66f9bbb9f229b0c97f07 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. 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
@@ -40,74 +40,6 @@ USB_MASS_TRANSPORT *mUsbMassTransport[] = {
   NULL\r
 };\r
 \r
-/**\r
-  Retrieve the media parameters such as disk gemotric for the\r
-  device's BLOCK IO protocol.\r
-\r
-  @param  UsbMass                The USB mass storage device\r
-\r
-  @retval EFI_SUCCESS            The media parameters is updated successfully.\r
-  @retval Others                 Failed to get the media parameters.\r
-\r
-**/\r
-EFI_STATUS\r
-UsbMassInitMedia (\r
-  IN USB_MASS_DEVICE          *UsbMass\r
-  )\r
-{\r
-  EFI_BLOCK_IO_MEDIA          *Media;\r
-  EFI_STATUS                  Status;\r
-  UINTN                       Index;\r
-\r
-  Media = &UsbMass->BlockIoMedia;\r
-\r
-  //\r
-  // Initialize the MediaPrsent/ReadOnly and others to the default.\r
-  // We are not forced to get it right at this time, check UEFI2.0\r
-  // spec for more information:\r
-  //\r
-  // MediaPresent: This field shows the media present status as\r
-  //               of the most recent ReadBlocks or WriteBlocks call.\r
-  //\r
-  // ReadOnly    : This field shows the read-only status as of the\r
-  //               recent WriteBlocks call.\r
-  //\r
-  // but remember to update MediaId/MediaPresent/ReadOnly status\r
-  // after ReadBlocks and WriteBlocks\r
-  //\r
-  Media->MediaPresent     = FALSE;\r
-  Media->LogicalPartition = FALSE;\r
-  Media->ReadOnly         = FALSE;\r
-  Media->WriteCaching     = FALSE;\r
-  Media->IoAlign          = 0;\r
-  Media->MediaId          = 1;\r
-\r
-  //\r
-  // Some device may spend several seconds before it is ready.\r
-  // Try several times before giving up. Wait 5s at most.\r
-  //\r
-  Status = EFI_SUCCESS;\r
-\r
-  for (Index = 0; Index < USB_BOOT_INIT_MEDIA_RETRY; Index++) {\r
-\r
-    Status = UsbBootGetParams (UsbMass);\r
-    if ((Status != EFI_MEDIA_CHANGED)\r
-        && (Status != EFI_NOT_READY)\r
-        && (Status != EFI_TIMEOUT)) {\r
-      break;\r
-    }\r
-\r
-    Status = UsbBootIsUnitReady (UsbMass);\r
-    if (EFI_ERROR (Status)) {\r
-      gBS->Stall (USB_BOOT_RETRY_UNIT_READY_STALL * (Index + 1));\r
-    }\r
-\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-\r
 /**\r
   Reset the block device. ExtendedVerification is ignored for this.\r
 \r
@@ -139,7 +71,6 @@ UsbMassReset (
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Read some blocks of data from the block device.\r
 \r
@@ -339,7 +270,6 @@ ON_EXIT:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Flush the cached writes to disks. USB mass storage device doesn't\r
   support write cache, so return EFI_SUCCESS directly.\r
@@ -358,6 +288,381 @@ UsbMassFlushBlocks (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Retrieve the media parameters such as disk gemotric for the\r
+  device's BLOCK IO protocol.\r
+\r
+  @param  UsbMass                The USB mass storage device\r
+\r
+  @retval EFI_SUCCESS            The media parameters is updated successfully.\r
+  @retval Others                 Failed to get the media parameters.\r
+\r
+**/\r
+EFI_STATUS\r
+UsbMassInitMedia (\r
+  IN USB_MASS_DEVICE          *UsbMass\r
+  )\r
+{\r
+  EFI_BLOCK_IO_MEDIA          *Media;\r
+  EFI_STATUS                  Status;\r
+  UINTN                       Index;\r
+\r
+  Media = &UsbMass->BlockIoMedia;\r
+\r
+  //\r
+  // Initialize the MediaPrsent/ReadOnly and others to the default.\r
+  // We are not forced to get it right at this time, check UEFI2.0\r
+  // spec for more information:\r
+  //\r
+  // MediaPresent: This field shows the media present status as\r
+  //               of the most recent ReadBlocks or WriteBlocks call.\r
+  //\r
+  // ReadOnly    : This field shows the read-only status as of the\r
+  //               recent WriteBlocks call.\r
+  //\r
+  // but remember to update MediaId/MediaPresent/ReadOnly status\r
+  // after ReadBlocks and WriteBlocks\r
+  //\r
+  Media->MediaPresent     = FALSE;\r
+  Media->LogicalPartition = FALSE;\r
+  Media->ReadOnly         = FALSE;\r
+  Media->WriteCaching     = FALSE;\r
+  Media->IoAlign          = 0;\r
+  Media->MediaId          = 1;\r
+\r
+  //\r
+  // Some device may spend several seconds before it is ready.\r
+  // Try several times before giving up. Wait 5s at most.\r
+  //\r
+  Status = EFI_SUCCESS;\r
+\r
+  for (Index = 0; Index < USB_BOOT_INIT_MEDIA_RETRY; Index++) {\r
+\r
+    Status = UsbBootGetParams (UsbMass);\r
+    if ((Status != EFI_MEDIA_CHANGED)\r
+        && (Status != EFI_NOT_READY)\r
+        && (Status != EFI_TIMEOUT)) {\r
+      break;\r
+    }\r
+\r
+    Status = UsbBootIsUnitReady (UsbMass);\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->Stall (USB_BOOT_RETRY_UNIT_READY_STALL * (Index + 1));\r
+    }\r
+\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UsbMassInitTransport (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Controller,\r
+  OUT USB_MASS_TRANSPORT           **Transport,\r
+  OUT VOID                         **Context,\r
+  OUT UINT8                        *MaxLun\r
+  )\r
+{\r
+  EFI_USB_IO_PROTOCOL           *UsbIo;\r
+  EFI_USB_INTERFACE_DESCRIPTOR  Interface;\r
+  UINT8                         Index;\r
+  EFI_STATUS                    Status;\r
\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiUsbIoProtocolGuid,\r
+                  &UsbIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "UsbMassInitTransport: OpenUsbIoProtocol By Driver (%r)\n", Status));\r
+    return Status;\r
+  }\r
+  \r
+  Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "UsbMassInitTransport: UsbIo->UsbGetInterfaceDescriptor (%r)\n", Status));\r
+    goto ON_EXIT;\r
+  }\r
+  \r
+  Status = EFI_UNSUPPORTED;\r
+\r
+  for (Index = 0; mUsbMassTransport[Index] != NULL; Index++) {\r
+    *Transport = mUsbMassTransport[Index];\r
+\r
+    if (Interface.InterfaceProtocol == (*Transport)->Protocol) {\r
+      Status  = (*Transport)->Init (UsbIo, Context);\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "UsbMassInitTransport: Transport->Init (%r)\n", Status));\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  //\r
+  // For bot device, try to get max lun. \r
+  // If maxlun=0, then non-lun device, else multi-lun device.\r
+  //\r
+  if ((*Transport)->Protocol == USB_MASS_STORE_BOT) {\r
+    (*Transport)->GetMaxLun (*Context, MaxLun);\r
+    DEBUG ((EFI_D_INFO, "UsbMassInitTransport: GetMaxLun = %d\n", *MaxLun));\r
+  }\r
+\r
+ON_EXIT:\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiUsbIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+  return Status;  \r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UsbMassInitMultiLun (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                    Controller,\r
+  IN USB_MASS_TRANSPORT            *Transport,\r
+  IN VOID                          *Context,\r
+  IN EFI_DEVICE_PATH_PROTOCOL      *DevicePath,\r
+  IN UINT8                         MaxLun\r
+  )\r
+{\r
+  USB_MASS_DEVICE                  *UsbMass;\r
+  EFI_USB_IO_PROTOCOL              *UsbIo;\r
+  DEVICE_LOGICAL_UNIT_DEVICE_PATH  LunNode;\r
+  UINT8                            Index;\r
+  EFI_STATUS                       Status;\r
+\r
+  ASSERT (MaxLun > 0);\r
+\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
+    UsbIo   = NULL;\r
+    UsbMass = AllocateZeroPool (sizeof (USB_MASS_DEVICE));\r
+    if (UsbMass == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto ON_ERROR;\r
+    }\r
+      \r
+    UsbMass->Signature            = USB_MASS_SIGNATURE;\r
+    UsbMass->UsbIo                = UsbIo;\r
+    UsbMass->BlockIo.Media        = &UsbMass->BlockIoMedia;\r
+    UsbMass->BlockIo.Reset        = UsbMassReset;\r
+    UsbMass->BlockIo.ReadBlocks   = UsbMassReadBlocks;\r
+    UsbMass->BlockIo.WriteBlocks  = UsbMassWriteBlocks;\r
+    UsbMass->BlockIo.FlushBlocks  = UsbMassFlushBlocks;\r
+    UsbMass->OpticalStorage       = FALSE;\r
+    UsbMass->Transport            = Transport;\r
+    UsbMass->Context              = Context;\r
+    UsbMass->Lun                  = Index;\r
+    \r
+    //\r
+    // Get the storage's parameters, such as last block number.\r
+    // then install the BLOCK_IO\r
+    //\r
+    Status = UsbMassInitMedia (UsbMass);\r
+    if (!EFI_ERROR (Status)) {\r
+      if ((UsbMass->Pdt != USB_PDT_DIRECT_ACCESS) && \r
+           (UsbMass->Pdt != USB_PDT_CDROM) &&\r
+           (UsbMass->Pdt != USB_PDT_OPTICAL) && \r
+           (UsbMass->Pdt != USB_PDT_SIMPLE_DIRECT)) {\r
+        DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt));\r
+        goto ON_ERROR;\r
+      }\r
+    } else if (Status != EFI_NO_MEDIA){\r
+      DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: UsbMassInitMedia (%r)\n", Status));\r
+      goto ON_ERROR;\r
+    }\r
+\r
+    //\r
+    // Create a device path node of device logic unit, and append it \r
+    //\r
+    LunNode.Header.Type    = MESSAGING_DEVICE_PATH;\r
+    LunNode.Header.SubType = MSG_DEVICE_LOGICAL_UNIT_DP;\r
+    LunNode.Lun            = UsbMass->Lun;\r
+  \r
+    SetDevicePathNodeLength (&LunNode.Header, sizeof (LunNode));\r
+  \r
+    UsbMass->DevicePath = AppendDevicePathNode (DevicePath, &LunNode.Header);\r
+  \r
+    if (UsbMass->DevicePath == NULL) {\r
+      DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: failed to create device logic unit device path\n"));\r
+  \r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto ON_ERROR;\r
+    }\r
+\r
+    //\r
+    // Create a UsbMass handle for each lun, and install blockio and devicepath protocols.\r
+    //\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &UsbMass->Controller,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    UsbMass->DevicePath,\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    &UsbMass->BlockIo,\r
+                    NULL\r
+                    );\r
+    \r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: InstallMultipleProtocolInterfaces (%r)\n", Status));\r
+      goto ON_ERROR;\r
+    }\r
+\r
+    //\r
+    // Open UsbIo protocol by child to setup a parent-child relationship.\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    Controller,\r
+                    &gEfiUsbIoProtocolGuid,\r
+                    &UsbIo,\r
+                    This->DriverBindingHandle,\r
+                    UsbMass->Controller,\r
+                    EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: OpenUsbIoProtocol By Child (%r)\n", Status));\r
+      gBS->UninstallMultipleProtocolInterfaces (\r
+             &UsbMass->Controller,\r
+             &gEfiDevicePathProtocolGuid,\r
+             UsbMass->DevicePath,\r
+             &gEfiBlockIoProtocolGuid,\r
+             &UsbMass->BlockIo,\r
+             NULL\r
+             );\r
+      goto ON_ERROR;\r
+    }\r
+    \r
+    DEBUG ((EFI_D_INFO, "UsbMassInitMultiLun: Success to initialize No.%d logic unit\n", Index));\r
+  }\r
+  \r
+  return EFI_SUCCESS;\r
+\r
+ON_ERROR:\r
+  if (UsbMass->DevicePath != NULL) {\r
+    gBS->FreePool (UsbMass->DevicePath);\r
+  }\r
+  if (UsbMass != NULL) {\r
+    gBS->FreePool (UsbMass);\r
+  }\r
+  if (UsbIo != NULL) {\r
+    gBS->CloseProtocol (\r
+           Controller,\r
+           &gEfiUsbIoProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           UsbMass->Controller\r
+           );\r
+  }\r
+\r
+  //\r
+  // If only success to initialize one lun, return success, or else return error\r
+  //\r
+  if (Index > 0) {\r
+    return EFI_SUCCESS; \r
+  } else {\r
+    return Status;\r
+  } \r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UsbMassInitNonLun (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN EFI_HANDLE                    Controller,\r
+  IN USB_MASS_TRANSPORT            *Transport,\r
+  IN VOID                          *Context\r
+  )\r
+{\r
+  USB_MASS_DEVICE             *UsbMass;\r
+  EFI_USB_IO_PROTOCOL         *UsbIo;\r
+  EFI_STATUS                  Status;\r
+\r
+  UsbIo   = NULL;\r
+  UsbMass = AllocateZeroPool (sizeof (USB_MASS_DEVICE));\r
+  if (UsbMass == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiUsbIoProtocolGuid,\r
+                  &UsbIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "UsbMassInitNonLun: OpenUsbIoProtocol By Driver (%r)\n", Status));\r
+    goto ON_ERROR;\r
+  }\r
+  \r
+  UsbMass->Signature            = USB_MASS_SIGNATURE;\r
+  UsbMass->Controller           = Controller;\r
+  UsbMass->UsbIo                = UsbIo;\r
+  UsbMass->BlockIo.Media        = &UsbMass->BlockIoMedia;\r
+  UsbMass->BlockIo.Reset        = UsbMassReset;\r
+  UsbMass->BlockIo.ReadBlocks   = UsbMassReadBlocks;\r
+  UsbMass->BlockIo.WriteBlocks  = UsbMassWriteBlocks;\r
+  UsbMass->BlockIo.FlushBlocks  = UsbMassFlushBlocks;\r
+  UsbMass->OpticalStorage       = FALSE;\r
+  UsbMass->Transport            = Transport;\r
+  UsbMass->Context              = Context;\r
+  \r
+  //\r
+  // Get the storage's parameters, such as last block number.\r
+  // then install the BLOCK_IO\r
+  //\r
+  Status = UsbMassInitMedia (UsbMass);\r
+  if (!EFI_ERROR (Status)) {\r
+    if ((UsbMass->Pdt != USB_PDT_DIRECT_ACCESS) && \r
+         (UsbMass->Pdt != USB_PDT_CDROM) &&\r
+         (UsbMass->Pdt != USB_PDT_OPTICAL) && \r
+         (UsbMass->Pdt != USB_PDT_SIMPLE_DIRECT)) {\r
+      DEBUG ((EFI_D_ERROR, "UsbMassInitNonLun: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt));\r
+      goto ON_ERROR;\r
+    }\r
+  } else if (Status != EFI_NO_MEDIA){\r
+    DEBUG ((EFI_D_ERROR, "UsbMassInitNonLun: UsbMassInitMedia (%r)\n", Status));\r
+    goto ON_ERROR;\r
+  }\r
+    \r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Controller,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &UsbMass->BlockIo\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+\r
+ON_ERROR:\r
+  if (UsbMass != NULL) {\r
+    gBS->FreePool (UsbMass);\r
+  }\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiUsbIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+  return Status;  \r
+}\r
+\r
 \r
 /**\r
   Check whether the controller is a supported USB mass storage.\r
@@ -418,7 +723,7 @@ USBMassDriverBindingSupported (
   for (Index = 0; mUsbMassTransport[Index] != NULL; Index++) {\r
     Transport = mUsbMassTransport[Index];\r
     if (Interface.InterfaceProtocol == Transport->Protocol) {\r
-      Status = Transport->Init (UsbIo, Controller, NULL);\r
+      Status = Transport->Init (UsbIo, NULL);\r
       break;\r
     }\r
   }\r
@@ -458,107 +763,65 @@ USBMassDriverBindingStart (
   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
   )\r
 {\r
-  EFI_USB_IO_PROTOCOL           *UsbIo;\r
-  EFI_USB_INTERFACE_DESCRIPTOR  Interface;\r
-  USB_MASS_DEVICE               *UsbMass;\r
   USB_MASS_TRANSPORT            *Transport;\r
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
+  VOID                          *Context;\r
+  UINT8                         MaxLun;\r
   EFI_STATUS                    Status;\r
-  UINTN                         Index;\r
-\r
-  Status = gBS->OpenProtocol (\r
-                  Controller,\r
-                  &gEfiUsbIoProtocolGuid,\r
-                  (VOID **) &UsbIo,\r
-                  This->DriverBindingHandle,\r
-                  Controller,\r
-                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  UsbMass = AllocateZeroPool (sizeof (USB_MASS_DEVICE));\r
-  if (UsbMass == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
+  \r
+  Transport = NULL;\r
+  Context   = NULL;\r
+  MaxLun    = 0;\r
 \r
   //\r
-  // Initialize the transport protocols\r
+  // Get interface and protocols, initialize transport\r
   //\r
-  Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbIo->UsbGetInterfaceDescriptor (%r)\n", Status));\r
-    goto ON_ERROR;\r
-  }\r
-\r
-  Status = EFI_UNSUPPORTED;\r
-\r
-  for (Index = 0; mUsbMassTransport[Index] != NULL; Index++) {\r
-    Transport = mUsbMassTransport[Index];\r
-\r
-    if (Interface.InterfaceProtocol == Transport->Protocol) {\r
-      UsbMass->Transport = Transport;\r
-      Status             = Transport->Init (UsbIo, Controller, &UsbMass->Context);\r
-      break;\r
-    }\r
-  }\r
+  Status = UsbMassInitTransport (This, Controller, &Transport, &Context, &MaxLun);\r
 \r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: Transport->Init (%r)\n", Status));\r
-    goto ON_ERROR;\r
+    DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitTransport (%r)\n", Status));\r
+    return Status;\r
   }\r
-\r
-  UsbMass->Signature            = USB_MASS_SIGNATURE;\r
-  UsbMass->Controller           = Controller;\r
-  UsbMass->UsbIo                = UsbIo;\r
-  UsbMass->BlockIo.Media        = &UsbMass->BlockIoMedia;\r
-  UsbMass->BlockIo.Reset        = UsbMassReset;\r
-  UsbMass->BlockIo.ReadBlocks   = UsbMassReadBlocks;\r
-  UsbMass->BlockIo.WriteBlocks  = UsbMassWriteBlocks;\r
-  UsbMass->BlockIo.FlushBlocks  = UsbMassFlushBlocks;\r
-  UsbMass->OpticalStorage       = FALSE;\r
-\r
-  //\r
-  // Get the storage's parameters, such as last block number.\r
-  // then install the BLOCK_IO\r
-  //\r
-  Status = UsbMassInitMedia (UsbMass);\r
-  if (!EFI_ERROR (Status)) {\r
-    if ((UsbMass->Pdt != USB_PDT_DIRECT_ACCESS) &&\r
-         (UsbMass->Pdt != USB_PDT_CDROM) &&\r
-         (UsbMass->Pdt != USB_PDT_OPTICAL) &&\r
-         (UsbMass->Pdt != USB_PDT_SIMPLE_DIRECT)) {\r
-      DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt));\r
-      goto ON_ERROR;\r
+  if (MaxLun == 0) {\r
+    //\r
+    // Initialize No/Unsupported LUN device\r
+    //\r
+    Status = UsbMassInitNonLun(This, Controller, Transport, Context);\r
+    if (EFI_ERROR (Status)) { \r
+      DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitNonLun (%r)\n", Status));\r
+    }\r
+  } else {\r
+    //\r
+    // Open device path to perpare append Device Logic Unit node.\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    Controller,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    (VOID **) &DevicePath,\r
+                    This->DriverBindingHandle,\r
+                    Controller,\r
+                    EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                    );\r
+  \r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: OpenDevicePathProtocol By Driver (%r)\n", Status));\r
+      return Status;\r
     }\r
-  } else if (Status != EFI_NO_MEDIA){\r
-    DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitMedia (%r)\n", Status));\r
-    goto ON_ERROR;\r
-  }\r
 \r
-  Status = gBS->InstallProtocolInterface (\r
-                  &Controller,\r
-                  &gEfiBlockIoProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  &UsbMass->BlockIo\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
+    //\r
+    // Try best to initialize all LUNs, and return success only if one of LUNs successed to initialized.\r
+    //\r
+    Status = UsbMassInitMultiLun(This, Controller, Transport, Context, DevicePath, MaxLun);\r
+    if (EFI_ERROR (Status)) {\r
+     gBS->CloseProtocol (\r
+            Controller,\r
+            &gEfiDevicePathProtocolGuid,\r
+            This->DriverBindingHandle,\r
+            Controller\r
+            );\r
+      DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitMultiLun (%r) with Maxlun=%d\n", Status, MaxLun));\r
+    }\r
   }\r
-\r
-  return EFI_SUCCESS;\r
-\r
-ON_ERROR:\r
-  gBS->FreePool (UsbMass);\r
-\r
-  gBS->CloseProtocol (\r
-        Controller,\r
-        &gEfiUsbIoProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Controller\r
-        );\r
-\r
   return Status;\r
 }\r
 \r
@@ -586,49 +849,151 @@ USBMassDriverBindingStop (
 {\r
   EFI_STATUS            Status;\r
   USB_MASS_DEVICE       *UsbMass;\r
+  EFI_USB_IO_PROTOCOL     *UsbIo;\r
   EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  UINTN                   Index;\r
+  BOOLEAN                 AllChildrenStopped;\r
 \r
   //\r
-  // First, get our context back from the BLOCK_IO\r
+  // This a bus driver stop function since multi-lun supported. There are three \r
+  // kinds of device handle might be passed, 1st is a handle with devicepath/\r
+  // usbio/blockio installed(non-multi-lun), 2nd is a handle with devicepath/\r
+  // usbio installed(multi-lun root), 3rd is a handle with devicepath/blockio\r
+  // installed(multi-lun).\r
   //\r
-  Status = gBS->OpenProtocol (\r
-                  Controller,\r
-                  &gEfiBlockIoProtocolGuid,\r
-                  (VOID **) &BlockIo,\r
-                  This->DriverBindingHandle,\r
-                  Controller,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  UsbMass = USB_MASS_DEVICE_FROM_BLOCKIO (BlockIo);\r
+  if (NumberOfChildren == 0) {\r
+    //\r
+    // A handle without any children, might be 1st and 2nd type.\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    Controller,\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    &BlockIo,\r
+                    This->DriverBindingHandle,\r
+                    Controller,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+  \r
+    if (EFI_ERROR(Status)) {\r
+      //\r
+      // This is a 2nd type handle(multi-lun root), which only needs close \r
+      // devicepath protocol.\r
+      //\r
+      gBS->CloseProtocol (\r
+            Controller,\r
+            &gEfiDevicePathProtocolGuid,\r
+            This->DriverBindingHandle,\r
+            Controller\r
+            );\r
+      DEBUG ((EFI_D_INFO, "Success to stop multi-lun root handle\n"));\r
+      return EFI_SUCCESS;\r
+    }\r
+    \r
+    //\r
+    // This is a 1st type handle(non-multi-lun), which only needs uninstall\r
+    // blockio protocol, close usbio protocol and free mass device.\r
+    //\r
+    UsbMass = USB_MASS_DEVICE_FROM_BLOCKIO (BlockIo);\r
+  \r
+    //\r
+    // Uninstall Block I/O protocol from the device handle,\r
+    // then call the transport protocol to stop itself.\r
+    //\r
+    Status = gBS->UninstallProtocolInterface (\r
+                    Controller,\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    &UsbMass->BlockIo\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  \r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiUsbIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+  \r
+    UsbMass->Transport->Fini (UsbMass->Context);\r
+    gBS->FreePool (UsbMass);\r
+    \r
+    DEBUG ((EFI_D_INFO, "Success to stop non-multi-lun root handle\n"));\r
+    return EFI_SUCCESS;\r
+  } \r
 \r
   //\r
-  // Uninstall Block I/O protocol from the device handle,\r
-  // then call the transport protocol to stop itself.\r
+  // This is a 3rd type handle(multi-lun), which needs uninstall\r
+  // blockio and devicepath protocol, close usbio protocol and \r
+  // free mass device.\r
   //\r
-  Status = gBS->UninstallProtocolInterface (\r
-                  Controller,\r
-                  &gEfiBlockIoProtocolGuid,\r
-                  &UsbMass->BlockIo\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  gBS->CloseProtocol (\r
-        Controller,\r
-        &gEfiUsbIoProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Controller\r
-        );\r
+  AllChildrenStopped = TRUE;\r
+\r
+  for (Index = 0; Index < NumberOfChildren; Index++) {\r
+\r
+    Status = gBS->OpenProtocol (\r
+                    ChildHandleBuffer[Index],\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    (VOID **) &BlockIo,\r
+                    This->DriverBindingHandle,\r
+                    Controller,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      AllChildrenStopped = FALSE;\r
+      DEBUG ((EFI_D_ERROR, "Fail to stop No.%d multi-lun child handle when opening blockio\n", Index));\r
+      continue;\r
+    }\r
 \r
-  UsbMass->Transport->Fini (UsbMass->Context);\r
-  gBS->FreePool (UsbMass);\r
+    UsbMass = USB_MASS_DEVICE_FROM_BLOCKIO (BlockIo);\r
+\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiUsbIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ChildHandleBuffer[Index]\r
+          );\r
+  \r
+    Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                    ChildHandleBuffer[Index],\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    UsbMass->DevicePath,\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    &UsbMass->BlockIo,\r
+                    NULL\r
+                    );\r
+    \r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Fail to uninstall blockio and devicepath protocol, so re-open usbio 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", Index));\r
+      \r
+      gBS->OpenProtocol (\r
+             Controller,\r
+             &gEfiUsbIoProtocolGuid,\r
+             &UsbIo,\r
+             This->DriverBindingHandle,\r
+             ChildHandleBuffer[Index],\r
+             EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+             );\r
+    } else {\r
+      //\r
+      // Success to stop this multi-lun handle, so go on next child.\r
+      //\r
+      if (((Index + 1) == NumberOfChildren) && AllChildrenStopped) {\r
+        UsbMass->Transport->Fini (UsbMass->Context);\r
+      }\r
+      gBS->FreePool (UsbMass);\r
+    }\r
+  }\r
 \r
+  if (!AllChildrenStopped) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  DEBUG ((EFI_D_INFO, "Success to stop all %d multi-lun children handles\n", NumberOfChildren));\r
   return EFI_SUCCESS;\r
 }\r
 \r
index e3952e40a4f778963f732ef0589312979dda32dc..93c65dde4f192b8b6ce8b8361620c9e69fad3f34 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. 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
@@ -43,16 +43,17 @@ enum {
 };\r
 \r
 struct _USB_MASS_DEVICE {\r
-  UINT32                Signature;\r
-  EFI_HANDLE            Controller;\r
-  EFI_USB_IO_PROTOCOL   *UsbIo;\r
-  EFI_BLOCK_IO_PROTOCOL BlockIo;\r
-  EFI_BLOCK_IO_MEDIA    BlockIoMedia;\r
-  BOOLEAN               OpticalStorage;\r
-  UINT8                 Lun;          // Logical Unit Number\r
-  UINT8                 Pdt;          // Peripheral Device Type\r
-  USB_MASS_TRANSPORT    *Transport;   // USB mass storage transport protocol\r
-  VOID                  *Context;     // Opaque storage for mass transport\r
+  UINT32                    Signature;\r
+  EFI_HANDLE                Controller;\r
+  EFI_USB_IO_PROTOCOL       *UsbIo;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_BLOCK_IO_PROTOCOL     BlockIo;\r
+  EFI_BLOCK_IO_MEDIA        BlockIoMedia;\r
+  BOOLEAN                   OpticalStorage;\r
+  UINT8                     Lun;          // Logical Unit Number\r
+  UINT8                     Pdt;          // Peripheral Device Type\r
+  USB_MASS_TRANSPORT        *Transport;   // USB mass storage transport protocol\r
+  VOID                      *Context;     // Opaque storage for mass transport\r
 };\r
 \r
 #define USB_MASS_DEVICE_FROM_BLOCKIO(a) \\r
index 347f65b740988a8518fbd7225c4a6471479576f9..eb4b2790a059caa7d577f85028856600d4888d07 100644 (file)
@@ -1,7 +1,7 @@
 #/** @file\r
 # Component name for module UsbMassStorage\r
 #\r
-# Copyright (c) 2006, Intel Corporation. \r
+# Copyright (c) 2006 - 2008, Intel Corporation. \r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
   UefiDriverEntryPoint\r
   BaseMemoryLib\r
   DebugLib\r
+  DevicePathLib\r
 \r
 \r
 [Protocols]\r
   gEfiUsbIoProtocolGuid                         # PROTOCOL ALWAYS_CONSUMED\r
   gEfiBlockIoProtocolGuid                       # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
 \r