Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 .../Universal/Disk/CdExpressPei/CdExpressPei.inf   |   5 +-
 .../Universal/Disk/CdExpressPei/PeiCdExpress.c     | 211 +++++++++++++++++----
 .../Universal/Disk/CdExpressPei/PeiCdExpress.h     |  20 +-
 3 files changed, 200 insertions(+), 36 deletions(-)

diff --git a/MdeModulePkg/Universal/Disk/CdExpressPei/CdExpressPei.inf 
b/MdeModulePkg/Universal/Disk/CdExpressPei/CdExpressPei.inf
index 4a44a5a..e9d45e5 100644
--- a/MdeModulePkg/Universal/Disk/CdExpressPei/CdExpressPei.inf
+++ b/MdeModulePkg/Universal/Disk/CdExpressPei/CdExpressPei.inf
@@ -5,7 +5,7 @@
 # finds whether there is Recovery data in the device. If it finds recovery
 # data, it will install Device Recovery Module PPI.
 #
-# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
 #
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions
@@ -60,6 +60,9 @@
   ## NOTIFY
   ## CONSUMES
   gEfiPeiVirtualBlockIoPpiGuid
+  ## NOTIFY
+  ## CONSUMES
+  gEfiPeiVirtualBlockIo2PpiGuid
   gEfiPeiDeviceRecoveryModulePpiGuid            ## PRODUCES
 
 [FeaturePcd]
diff --git a/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.c 
b/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.c
index dccb460..00fde4c 100644
--- a/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.c
+++ b/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.c
@@ -1,7 +1,7 @@
 /** @file
   Source file for CD recovery PEIM
 
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -60,7 +60,8 @@ CdExpressPeimEntry (
   }
 
   PrivateData->CapsuleCount = 0;
-  Status                    = UpdateBlocksAndVolumes (PrivateData);
+  Status = UpdateBlocksAndVolumes2 (PrivateData);
+  Status = UpdateBlocksAndVolumes (PrivateData);
 
   //
   // Installs Ppi
@@ -69,9 +70,9 @@ CdExpressPeimEntry (
   PrivateData->DeviceRecoveryPpi.GetRecoveryCapsuleInfo     = 
GetRecoveryCapsuleInfo;
   PrivateData->DeviceRecoveryPpi.LoadRecoveryCapsule        = 
LoadRecoveryCapsule;
 
-  PrivateData->PpiDescriptor.Flags                          = 
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
-  PrivateData->PpiDescriptor.Guid = &gEfiPeiDeviceRecoveryModulePpiGuid;
-  PrivateData->PpiDescriptor.Ppi = &PrivateData->DeviceRecoveryPpi;
+  PrivateData->PpiDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | 
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
+  PrivateData->PpiDescriptor.Guid  = &gEfiPeiDeviceRecoveryModulePpiGuid;
+  PrivateData->PpiDescriptor.Ppi   = &PrivateData->DeviceRecoveryPpi;
 
   Status = PeiServicesInstallPpi (&PrivateData->PpiDescriptor);
   if (EFI_ERROR (Status)) {
@@ -87,11 +88,19 @@ CdExpressPeimEntry (
   //
   PrivateData->NotifyDescriptor.Flags =
     (
-      EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
-      EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
+      EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
     );
   PrivateData->NotifyDescriptor.Guid    = &gEfiPeiVirtualBlockIoPpiGuid;
   PrivateData->NotifyDescriptor.Notify  = BlockIoNotifyEntry;
+
+  PrivateData->NotifyDescriptor2.Flags =
+    (
+      EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
+      EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
+    );
+  PrivateData->NotifyDescriptor2.Guid    = &gEfiPeiVirtualBlockIo2PpiGuid;
+  PrivateData->NotifyDescriptor2.Notify  = BlockIoNotifyEntry;
+
   return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor);
 
 }
@@ -117,7 +126,11 @@ BlockIoNotifyEntry (
   IN VOID                       *Ppi
   )
 {
-  UpdateBlocksAndVolumes (mPrivateData);
+  if (CompareGuid (NotifyDescriptor->Guid, &gEfiPeiVirtualBlockIo2PpiGuid)) {
+    UpdateBlocksAndVolumes2 (mPrivateData);
+  } else {
+    UpdateBlocksAndVolumes (mPrivateData);
+  }
 
   return EFI_SUCCESS;
 }
@@ -196,7 +209,7 @@ UpdateBlocksAndVolumes (
       DEBUG ((EFI_D_INFO, "PeiCdExpress Status is %d\n", Status));
 
       DEBUG ((EFI_D_INFO, "IndexBlockDevice is %d\n", IndexBlockDevice));
-      PrivateData->CapsuleData[PrivateData->CapsuleCount].IndexBlock = 
IndexBlockDevice;  
+      PrivateData->CapsuleData[PrivateData->CapsuleCount].IndexBlock = 
IndexBlockDevice;
       PrivateData->CapsuleData[PrivateData->CapsuleCount].BlockIo    = 
BlockIoPpi;
       Status = FindRecoveryCapsules (PrivateData);
       DEBUG ((EFI_D_INFO, "Status is %d\n", Status));
@@ -214,6 +227,97 @@ UpdateBlocksAndVolumes (
 }
 
 /**
+  Finds out all the current Block IO 2 PPIs in the system and add them into 
private data.
+
+  @param PrivateData                    The private data structure that 
contains recovery module information.
+
+  @retval EFI_SUCCESS                   The blocks and volumes are updated 
successfully.
+
+**/
+EFI_STATUS
+UpdateBlocksAndVolumes2 (
+  IN OUT PEI_CD_EXPRESS_PRIVATE_DATA     *PrivateData
+  )
+{
+  EFI_STATUS                      Status;
+  EFI_PEI_PPI_DESCRIPTOR          *TempPpiDescriptor;
+  UINTN                           BlockIoPpiInstance;
+  EFI_PEI_RECOVERY_BLOCK_IO2_PPI  *BlockIo2Ppi;
+  UINTN                           NumberBlockDevices;
+  UINTN                           IndexBlockDevice;
+  EFI_PEI_BLOCK_IO2_MEDIA         Media;
+  EFI_PEI_SERVICES                **PeiServices;
+
+  IndexBlockDevice = 0;
+  //
+  // Find out all Block Io Ppi instances within the system
+  // Assuming all device Block Io Peims are dispatched already
+  //
+  for (BlockIoPpiInstance = 0; BlockIoPpiInstance < 
PEI_CD_EXPRESS_MAX_BLOCK_IO_PPI; BlockIoPpiInstance++) {
+    Status = PeiServicesLocatePpi (
+                              &gEfiPeiVirtualBlockIo2PpiGuid,
+                              BlockIoPpiInstance,
+                              &TempPpiDescriptor,
+                              (VOID **) &BlockIo2Ppi
+                              );
+    if (EFI_ERROR (Status)) {
+      //
+      // Done with all Block Io Ppis
+      //
+      break;
+    }
+
+    PeiServices = (EFI_PEI_SERVICES  **) GetPeiServicesTablePointer ();
+    Status = BlockIo2Ppi->GetNumberOfBlockDevices (
+                          PeiServices,
+                          BlockIo2Ppi,
+                          &NumberBlockDevices
+                          );
+    if (EFI_ERROR (Status) || (NumberBlockDevices == 0)) {
+      continue;
+    }
+    //
+    // Just retrieve the first block, should emulate all blocks.
+    //
+    for (IndexBlockDevice = 1; IndexBlockDevice <= NumberBlockDevices && 
PrivateData->CapsuleCount < PEI_CD_EXPRESS_MAX_CAPSULE_NUMBER; IndexBlockDevice 
++) {
+      Status = BlockIo2Ppi->GetBlockDeviceMediaInfo (
+                            PeiServices,
+                            BlockIo2Ppi,
+                            IndexBlockDevice,
+                            &Media
+                            );
+      if (EFI_ERROR (Status) ||
+          !Media.MediaPresent ||
+           ((Media.InterfaceType != MSG_ATAPI_DP) && (Media.InterfaceType != 
MSG_USB_DP)) ||
+          (Media.BlockSize != PEI_CD_BLOCK_SIZE)
+          ) {
+        continue;
+      }
+
+      DEBUG ((EFI_D_INFO, "PeiCdExpress InterfaceType is %d\n", 
Media.InterfaceType));
+      DEBUG ((EFI_D_INFO, "PeiCdExpress MediaPresent is %d\n", 
Media.MediaPresent));
+      DEBUG ((EFI_D_INFO, "PeiCdExpress BlockSize is  0x%x\n", 
Media.BlockSize));
+      DEBUG ((EFI_D_INFO, "PeiCdExpress Status is %d\n", Status));
+
+      DEBUG ((EFI_D_INFO, "IndexBlockDevice is %d\n", IndexBlockDevice));
+      PrivateData->CapsuleData[PrivateData->CapsuleCount].IndexBlock = 
IndexBlockDevice;
+      PrivateData->CapsuleData[PrivateData->CapsuleCount].BlockIo2   = 
BlockIo2Ppi;
+      Status = FindRecoveryCapsules (PrivateData);
+      DEBUG ((EFI_D_INFO, "Status is %d\n", Status));
+
+      if (EFI_ERROR (Status)) {
+        continue;
+      }
+
+      PrivateData->CapsuleCount++;
+    }
+
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
   Finds out the recovery capsule in the current volume.
 
   @param PrivateData                    The private data structure that 
contains recovery module information.
@@ -231,6 +335,7 @@ FindRecoveryCapsules (
   EFI_STATUS                      Status;
   UINTN                           Lba;
   EFI_PEI_RECOVERY_BLOCK_IO_PPI   *BlockIoPpi;
+  EFI_PEI_RECOVERY_BLOCK_IO2_PPI  *BlockIo2Ppi;
   UINTN                           BufferSize;
   UINT8                           *Buffer;
   UINT8                           Type;
@@ -251,6 +356,7 @@ FindRecoveryCapsules (
   //
   IndexBlockDevice = 
PrivateData->CapsuleData[PrivateData->CapsuleCount].IndexBlock;
   BlockIoPpi       = 
PrivateData->CapsuleData[PrivateData->CapsuleCount].BlockIo;
+  BlockIo2Ppi      = 
PrivateData->CapsuleData[PrivateData->CapsuleCount].BlockIo2;
 
   VolumeSpaceSize = 0;
   StartOfVolume   = TRUE;
@@ -258,14 +364,25 @@ FindRecoveryCapsules (
 
   while (TRUE) {
     SetMem (Buffer, BufferSize, 0);
-    Status = BlockIoPpi->ReadBlocks (
-                          (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
-                          BlockIoPpi,
-                          IndexBlockDevice,
-                          Lba,
-                          BufferSize,
-                          Buffer
-                          );
+    if (BlockIo2Ppi != NULL) {
+      Status = BlockIo2Ppi->ReadBlocks (
+                            (EFI_PEI_SERVICES **) GetPeiServicesTablePointer 
(),
+                            BlockIo2Ppi,
+                            IndexBlockDevice,
+                            Lba,
+                            BufferSize,
+                            Buffer
+                            );
+    } else {
+      Status = BlockIoPpi->ReadBlocks (
+                            (EFI_PEI_SERVICES **) GetPeiServicesTablePointer 
(),
+                            BlockIoPpi,
+                            IndexBlockDevice,
+                            Lba,
+                            BufferSize,
+                            Buffer
+                            );
+    }
     if (EFI_ERROR (Status)) {
       return Status;
     }
@@ -302,7 +419,7 @@ FindRecoveryCapsules (
     RoorDirRecord   = (PEI_CD_EXPRESS_DIR_FILE_RECORD *) (Buffer + 
PEI_CD_EXPRESS_ROOT_DIR_RECORD_OFFSET);
     RootDirLBA      = RoorDirRecord->LocationOfExtent[0];
 
-    Status          = RetrieveCapsuleFileFromRoot (PrivateData, BlockIoPpi, 
IndexBlockDevice, RootDirLBA);
+    Status          = RetrieveCapsuleFileFromRoot (PrivateData, BlockIoPpi, 
BlockIo2Ppi, IndexBlockDevice, RootDirLBA);
     if (!EFI_ERROR (Status)) {
       //
       // Just look for the first primary descriptor
@@ -321,6 +438,7 @@ FindRecoveryCapsules (
 
   @param PrivateData                    The private data structure that 
contains recovery module information.
   @param BlockIoPpi                     The Block IO PPI used to access the 
volume.
+  @param BlockIo2Ppi                    The Block IO 2 PPI used to access the 
volume.
   @param IndexBlockDevice               The index of current block device.
   @param Lba                            The starting logic block address to 
retrieve capsule.
 
@@ -334,6 +452,7 @@ EFIAPI
 RetrieveCapsuleFileFromRoot (
   IN OUT PEI_CD_EXPRESS_PRIVATE_DATA        *PrivateData,
   IN EFI_PEI_RECOVERY_BLOCK_IO_PPI          *BlockIoPpi,
+  IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI         *BlockIo2Ppi,
   IN UINTN                                  IndexBlockDevice,
   IN UINT32                                 Lba
   )
@@ -349,14 +468,25 @@ RetrieveCapsuleFileFromRoot (
 
   SetMem (Buffer, BufferSize, 0);
 
-  Status = BlockIoPpi->ReadBlocks (
-                        (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
-                        BlockIoPpi,
-                        IndexBlockDevice,
-                        Lba,
-                        BufferSize,
-                        Buffer
-                        );
+  if (BlockIo2Ppi != NULL) {
+    Status = BlockIo2Ppi->ReadBlocks (
+                          (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
+                          BlockIo2Ppi,
+                          IndexBlockDevice,
+                          Lba,
+                          BufferSize,
+                          Buffer
+                          );
+  } else {
+    Status = BlockIoPpi->ReadBlocks (
+                          (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
+                          BlockIoPpi,
+                          IndexBlockDevice,
+                          Lba,
+                          BufferSize,
+                          Buffer
+                          );
+  }
   if (EFI_ERROR (Status)) {
     return Status;
   }
@@ -546,6 +676,7 @@ LoadRecoveryCapsule (
   EFI_STATUS                      Status;
   PEI_CD_EXPRESS_PRIVATE_DATA     *PrivateData;
   EFI_PEI_RECOVERY_BLOCK_IO_PPI   *BlockIoPpi;
+  EFI_PEI_RECOVERY_BLOCK_IO2_PPI  *BlockIo2Ppi;
   UINTN                           NumberRecoveryCapsules;
 
   Status = GetNumberRecoveryCapsules (PeiServices, This, 
&NumberRecoveryCapsules);
@@ -564,15 +695,27 @@ LoadRecoveryCapsule (
 
   PrivateData = PEI_CD_EXPRESS_PRIVATE_DATA_FROM_THIS (This);
   BlockIoPpi  = PrivateData->CapsuleData[CapsuleInstance - 1].BlockIo;
+  BlockIo2Ppi = PrivateData->CapsuleData[CapsuleInstance - 1].BlockIo2;
 
-  Status = BlockIoPpi->ReadBlocks (
-                        PeiServices,
-                        BlockIoPpi,
-                        PrivateData->CapsuleData[CapsuleInstance - 
1].IndexBlock,
-                        PrivateData->CapsuleData[CapsuleInstance - 
1].CapsuleStartLBA,
-                        PrivateData->CapsuleData[CapsuleInstance - 
1].CapsuleSize,
-                        Buffer
-                        );
+  if (BlockIo2Ppi != NULL) {
+    Status = BlockIo2Ppi->ReadBlocks (
+                          PeiServices,
+                          BlockIo2Ppi,
+                          PrivateData->CapsuleData[CapsuleInstance - 
1].IndexBlock,
+                          PrivateData->CapsuleData[CapsuleInstance - 
1].CapsuleStartLBA,
+                          PrivateData->CapsuleData[CapsuleInstance - 
1].CapsuleSize,
+                          Buffer
+                          );
+  } else {
+    Status = BlockIoPpi->ReadBlocks (
+                          PeiServices,
+                          BlockIoPpi,
+                          PrivateData->CapsuleData[CapsuleInstance - 
1].IndexBlock,
+                          PrivateData->CapsuleData[CapsuleInstance - 
1].CapsuleStartLBA,
+                          PrivateData->CapsuleData[CapsuleInstance - 
1].CapsuleSize,
+                          Buffer
+                          );
+  }
   return Status;
 }
 
diff --git a/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.h 
b/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.h
index b452747..7789a1b 100644
--- a/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.h
+++ b/MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.h
@@ -1,7 +1,7 @@
 /** @file
   Header file for CD recovery PEIM
 
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #include <PiPei.h>
 
 #include <Ppi/BlockIo.h>
+#include <Ppi/BlockIo2.h>
 #include <Guid/RecoveryDevice.h>
 #include <Ppi/DeviceRecoveryModule.h>
 
@@ -67,6 +68,7 @@ typedef struct {
   UINTN                           CapsuleSize;
   UINTN                           IndexBlock;
   EFI_PEI_RECOVERY_BLOCK_IO_PPI   *BlockIo;
+  EFI_PEI_RECOVERY_BLOCK_IO2_PPI  *BlockIo2;
 } PEI_CD_EXPRESS_CAPSULE_DATA;
 
 #define PEI_CD_EXPRESS_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'c', 'd', 'e')
@@ -77,6 +79,7 @@ typedef struct {
   EFI_PEI_DEVICE_RECOVERY_MODULE_PPI    DeviceRecoveryPpi;
   EFI_PEI_PPI_DESCRIPTOR                PpiDescriptor;
   EFI_PEI_NOTIFY_DESCRIPTOR             NotifyDescriptor;
+  EFI_PEI_NOTIFY_DESCRIPTOR             NotifyDescriptor2;
 
   UINT8                                 *BlockBuffer;
   UINTN                                 CapsuleCount;
@@ -140,6 +143,19 @@ UpdateBlocksAndVolumes (
   );
 
 /**
+  Finds out all the current Block IO 2 PPIs in the system and add them into 
private data.
+
+  @param PrivateData                    The private data structure that 
contains recovery module information.
+
+  @retval EFI_SUCCESS                   The blocks and volumes are updated 
successfully.
+
+**/
+EFI_STATUS
+UpdateBlocksAndVolumes2 (
+  IN OUT PEI_CD_EXPRESS_PRIVATE_DATA     *PrivateData
+  );
+
+/**
   Returns the number of DXE capsules residing on the device.
 
   This function searches for DXE capsules from the associated device and 
returns
@@ -253,6 +269,7 @@ FindRecoveryCapsules (
 
   @param PrivateData                    The private data structure that 
contains recovery module information.
   @param BlockIoPpi                     The Block IO PPI used to access the 
volume.
+  @param BlockIo2Ppi                    The Block IO 2 PPI used to access the 
volume.
   @param IndexBlockDevice               The index of current block device.
   @param Lba                            The starting logic block address to 
retrieve capsule.
 
@@ -266,6 +283,7 @@ EFIAPI
 RetrieveCapsuleFileFromRoot (
   IN OUT PEI_CD_EXPRESS_PRIVATE_DATA        *PrivateData,
   IN EFI_PEI_RECOVERY_BLOCK_IO_PPI          *BlockIoPpi,
+  IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI         *BlockIo2Ppi,
   IN UINTN                                  IndexBlockDevice,
   IN UINT32                                 Lba
   );
-- 
1.9.5.msysgit.0


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to