]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg RamDiskDxe: Install Block I/O 2 Protocol on RAM disk devices
authorHao Wu <hao.a.wu@intel.com>
Wed, 17 Feb 2016 03:25:14 +0000 (11:25 +0800)
committerHao Wu <hao.a.wu@intel.com>
Mon, 29 Feb 2016 05:51:19 +0000 (13:51 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Samer El-Haj-Mahmoud <elhaj@hpe.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c

index 1687da36902d24dc436511ada371e15e08cf0725..f36e1c8ff27b56e952459f1b4a44ba8f600b57c2 100644 (file)
@@ -27,9 +27,21 @@ EFI_BLOCK_IO_PROTOCOL  mRamDiskBlockIoTemplate = {
   RamDiskBlkIoFlushBlocks\r
 };\r
 \r
+//\r
+// The EFI_BLOCK_IO_PROTOCOL2 instances that is installed onto the handle\r
+// for newly registered RAM disks\r
+//\r
+EFI_BLOCK_IO2_PROTOCOL  mRamDiskBlockIo2Template = {\r
+  (EFI_BLOCK_IO_MEDIA *) 0,\r
+  RamDiskBlkIo2Reset,\r
+  RamDiskBlkIo2ReadBlocksEx,\r
+  RamDiskBlkIo2WriteBlocksEx,\r
+  RamDiskBlkIo2FlushBlocksEx\r
+};\r
+\r
 \r
 /**\r
-  Initialize the BlockIO protocol of a RAM disk device.\r
+  Initialize the BlockIO & BlockIO2 protocol of a RAM disk device.\r
 \r
   @param[in] PrivateData     Points to RAM disk private data.\r
 \r
@@ -40,14 +52,18 @@ RamDiskInitBlockIo (
   )\r
 {\r
   EFI_BLOCK_IO_PROTOCOL           *BlockIo;\r
+  EFI_BLOCK_IO2_PROTOCOL          *BlockIo2;\r
   EFI_BLOCK_IO_MEDIA              *Media;\r
 \r
-  BlockIo = &PrivateData->BlockIo;\r
-  Media   = &PrivateData->Media;\r
+  BlockIo  = &PrivateData->BlockIo;\r
+  BlockIo2 = &PrivateData->BlockIo2;\r
+  Media    = &PrivateData->Media;\r
 \r
   CopyMem (BlockIo, &mRamDiskBlockIoTemplate, sizeof (EFI_BLOCK_IO_PROTOCOL));\r
+  CopyMem (BlockIo2, &mRamDiskBlockIo2Template, sizeof (EFI_BLOCK_IO2_PROTOCOL));\r
 \r
   BlockIo->Media          = Media;\r
+  BlockIo2->Media         = Media;\r
   Media->RemovableMedia   = FALSE;\r
   Media->MediaPresent     = TRUE;\r
   Media->LogicalPartition = FALSE;\r
@@ -256,3 +272,214 @@ RamDiskBlkIoFlushBlocks (
 {\r
   return EFI_SUCCESS;\r
 }\r
+\r
+\r
+/**\r
+  Resets the block device hardware.\r
+\r
+  @param[in] This                 The pointer of EFI_BLOCK_IO2_PROTOCOL.\r
+  @param[in] ExtendedVerification The flag about if extend verificate.\r
+\r
+  @retval EFI_SUCCESS             The device was reset.\r
+  @retval EFI_DEVICE_ERROR        The block device is not functioning correctly\r
+                                  and could not be reset.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RamDiskBlkIo2Reset (\r
+  IN EFI_BLOCK_IO2_PROTOCOL       *This,\r
+  IN BOOLEAN                      ExtendedVerification\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Reads the requested number of blocks from the device.\r
+\r
+  @param[in]      This            Indicates a pointer to the calling context.\r
+  @param[in]      MediaId         The media ID that the read request is for.\r
+  @param[in]      Lba             The starting logical block address to read\r
+                                  from on the device.\r
+  @param[in, out] Token           A pointer to the token associated with the\r
+                                  transaction.\r
+  @param[in]      BufferSize      The size of the Buffer in bytes. This must be\r
+                                  a multiple of the intrinsic block size of the\r
+                                  device.\r
+  @param[out]     Buffer          A pointer to the destination buffer for the\r
+                                  data. The caller is responsible for either\r
+                                  having implicit or explicit ownership of the\r
+                                  buffer.\r
+\r
+  @retval EFI_SUCCESS             The read request was queued if Token->Event\r
+                                  is not NULL. The data was read correctly from\r
+                                  the device if the Token->Event is NULL.\r
+  @retval EFI_DEVICE_ERROR        The device reported an error while attempting\r
+                                  to perform the read operation.\r
+  @retval EFI_NO_MEDIA            There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED       The MediaId is not for the current media.\r
+  @retval EFI_BAD_BUFFER_SIZE     The BufferSize parameter is not a multiple of\r
+                                  the intrinsic block size of the device.\r
+  @retval EFI_INVALID_PARAMETER   The read request contains LBAs that are not\r
+                                  valid, or the buffer is not on proper\r
+                                  alignment.\r
+  @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a\r
+                                  lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RamDiskBlkIo2ReadBlocksEx (\r
+  IN     EFI_BLOCK_IO2_PROTOCOL   *This,\r
+  IN     UINT32                   MediaId,\r
+  IN     EFI_LBA                  Lba,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN      *Token,\r
+  IN     UINTN                    BufferSize,\r
+     OUT VOID                     *Buffer\r
+  )\r
+{\r
+  RAM_DISK_PRIVATE_DATA           *PrivateData;\r
+  EFI_STATUS                      Status;\r
+\r
+  PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO2 (This);\r
+\r
+  Status = RamDiskBlkIoReadBlocks (\r
+              &PrivateData->BlockIo,\r
+              MediaId,\r
+              Lba,\r
+              BufferSize,\r
+              Buffer\r
+              );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // If caller's event is given, signal it after the memory read completes.\r
+  //\r
+  if ((Token != NULL) && (Token->Event != NULL)) {\r
+    Token->TransactionStatus = EFI_SUCCESS;\r
+    gBS->SignalEvent (Token->Event);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Writes a specified number of blocks to the device.\r
+\r
+  @param[in]      This            Indicates a pointer to the calling context.\r
+  @param[in]      MediaId         The media ID that the write request is for.\r
+  @param[in]      Lba             The starting logical block address to be\r
+                                  written. The caller is responsible for\r
+                                  writing to only legitimate locations.\r
+  @param[in, out] Token           A pointer to the token associated with the\r
+                                  transaction.\r
+  @param[in]      BufferSize      The size in bytes of Buffer. This must be a\r
+                                  multiple of the intrinsic block size of the\r
+                                  device.\r
+  @param[in]      Buffer          A pointer to the source buffer for the data.\r
+\r
+  @retval EFI_SUCCESS             The write request was queued if Event is not\r
+                                  NULL. The data was written correctly to the\r
+                                  device if the Event is NULL.\r
+  @retval EFI_WRITE_PROTECTED     The device cannot be written to.\r
+  @retval EFI_NO_MEDIA            There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED       The MediaId is not for the current media.\r
+  @retval EFI_DEVICE_ERROR        The device reported an error while attempting\r
+                                  to perform the write operation.\r
+  @retval EFI_BAD_BUFFER_SIZE     The BufferSize parameter is not a multiple of\r
+                                  the intrinsic block size of the device.\r
+  @retval EFI_INVALID_PARAMETER   The write request contains LBAs that are not\r
+                                  valid, or the buffer is not on proper\r
+                                  alignment.\r
+  @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a\r
+                                  lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RamDiskBlkIo2WriteBlocksEx (\r
+  IN     EFI_BLOCK_IO2_PROTOCOL   *This,\r
+  IN     UINT32                   MediaId,\r
+  IN     EFI_LBA                  Lba,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN      *Token,\r
+  IN     UINTN                    BufferSize,\r
+  IN     VOID                     *Buffer\r
+  )\r
+{\r
+  RAM_DISK_PRIVATE_DATA           *PrivateData;\r
+  EFI_STATUS                      Status;\r
+\r
+  PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO2 (This);\r
+\r
+  Status = RamDiskBlkIoWriteBlocks (\r
+              &PrivateData->BlockIo,\r
+              MediaId,\r
+              Lba,\r
+              BufferSize,\r
+              Buffer\r
+              );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // If caller's event is given, signal it after the memory write completes.\r
+  //\r
+  if ((Token != NULL) && (Token->Event != NULL)) {\r
+    Token->TransactionStatus = EFI_SUCCESS;\r
+    gBS->SignalEvent (Token->Event);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Flushes all modified data to a physical block device.\r
+\r
+  @param[in]      This            Indicates a pointer to the calling context.\r
+  @param[in, out] Token           A pointer to the token associated with the\r
+                                  transaction.\r
+\r
+  @retval EFI_SUCCESS             The flush request was queued if Event is not\r
+                                  NULL. All outstanding data was written\r
+                                  correctly to the device if the Event is NULL.\r
+  @retval EFI_DEVICE_ERROR        The device reported an error while attempting\r
+                                  to write data.\r
+  @retval EFI_WRITE_PROTECTED     The device cannot be written to.\r
+  @retval EFI_NO_MEDIA            There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED       The MediaId is not for the current media.\r
+  @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a\r
+                                  lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RamDiskBlkIo2FlushBlocksEx (\r
+  IN     EFI_BLOCK_IO2_PROTOCOL   *This,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN      *Token\r
+  )\r
+{\r
+  RAM_DISK_PRIVATE_DATA           *PrivateData;\r
+\r
+  PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO2 (This);\r
+\r
+  if (TRUE == PrivateData->Media.ReadOnly) {\r
+    return EFI_WRITE_PROTECTED;\r
+  }\r
+\r
+  //\r
+  // If caller's event is given, signal it directly.\r
+  //\r
+  if ((Token != NULL) && (Token->Event != NULL)) {\r
+    Token->TransactionStatus = EFI_SUCCESS;\r
+    gBS->SignalEvent (Token->Event);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
index 85913c55cb34ed7a236243cb75906bed36b5804f..9fe35996ee35221564e6c853ce4e31e4277e0465 100644 (file)
@@ -71,6 +71,7 @@
   gEfiHiiConfigAccessProtocolGuid                ## PRODUCES\r
   gEfiDevicePathProtocolGuid                     ## PRODUCES\r
   gEfiBlockIoProtocolGuid                        ## PRODUCES\r
+  gEfiBlockIo2ProtocolGuid                       ## PRODUCES\r
   gEfiSimpleFileSystemProtocolGuid               ## SOMETIMES_CONSUMES\r
 \r
 [Depex]\r
index a2c48b23e38ccc33f5c4073eb21df8c55d51f3fe..b5770dd85ab64ef52109825540ffea1023d2985b 100644 (file)
@@ -173,6 +173,8 @@ UnregisterAllRamDisks (
              PrivateData->Handle,\r
              &gEfiBlockIoProtocolGuid,\r
              &PrivateData->BlockIo,\r
+             &gEfiBlockIo2ProtocolGuid,\r
+             &PrivateData->BlockIo2,\r
              &gEfiDevicePathProtocolGuid,\r
              (EFI_DEVICE_PATH_PROTOCOL *) PrivateData->DevicePath,\r
              NULL\r
index 47250068d70e0fe97369fb4e72ebab7879bb0999..0b9a4f9ec832bf437f6fb34ede05a34812111b93 100644 (file)
@@ -30,6 +30,7 @@
 #include <Library/PrintLib.h>\r
 #include <Protocol/RamDisk.h>\r
 #include <Protocol/BlockIo.h>\r
+#include <Protocol/BlockIo2.h>\r
 #include <Protocol/HiiConfigAccess.h>\r
 #include <Protocol/SimpleFileSystem.h>\r
 #include <Guid/MdeModuleHii.h>\r
@@ -86,6 +87,7 @@ typedef struct {
   EFI_HANDLE                      Handle;\r
 \r
   EFI_BLOCK_IO_PROTOCOL           BlockIo;\r
+  EFI_BLOCK_IO2_PROTOCOL          BlockIo2;\r
   EFI_BLOCK_IO_MEDIA              Media;\r
   EFI_DEVICE_PATH_PROTOCOL        *DevicePath;\r
 \r
@@ -100,6 +102,7 @@ typedef struct {
 \r
 #define RAM_DISK_PRIVATE_DATA_SIGNATURE     SIGNATURE_32 ('R', 'D', 'S', 'K')\r
 #define RAM_DISK_PRIVATE_FROM_BLKIO(a)      CR (a, RAM_DISK_PRIVATE_DATA, BlockIo, RAM_DISK_PRIVATE_DATA_SIGNATURE)\r
+#define RAM_DISK_PRIVATE_FROM_BLKIO2(a)     CR (a, RAM_DISK_PRIVATE_DATA, BlockIo2, RAM_DISK_PRIVATE_DATA_SIGNATURE)\r
 #define RAM_DISK_PRIVATE_FROM_THIS(a)       CR (a, RAM_DISK_PRIVATE_DATA, ThisInstance, RAM_DISK_PRIVATE_DATA_SIGNATURE)\r
 \r
 ///\r
@@ -310,6 +313,137 @@ RamDiskBlkIoFlushBlocks (
   IN EFI_BLOCK_IO_PROTOCOL        *This\r
   );\r
 \r
+/**\r
+  Resets the block device hardware.\r
+\r
+  @param[in] This                 The pointer of EFI_BLOCK_IO2_PROTOCOL.\r
+  @param[in] ExtendedVerification The flag about if extend verificate.\r
+\r
+  @retval EFI_SUCCESS             The device was reset.\r
+  @retval EFI_DEVICE_ERROR        The block device is not functioning correctly\r
+                                  and could not be reset.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RamDiskBlkIo2Reset (\r
+  IN EFI_BLOCK_IO2_PROTOCOL       *This,\r
+  IN BOOLEAN                      ExtendedVerification\r
+  );\r
+\r
+/**\r
+  Reads the requested number of blocks from the device.\r
+\r
+  @param[in]      This            Indicates a pointer to the calling context.\r
+  @param[in]      MediaId         The media ID that the read request is for.\r
+  @param[in]      Lba             The starting logical block address to read\r
+                                  from on the device.\r
+  @param[in, out] Token           A pointer to the token associated with the\r
+                                  transaction.\r
+  @param[in]      BufferSize      The size of the Buffer in bytes. This must be\r
+                                  a multiple of the intrinsic block size of the\r
+                                  device.\r
+  @param[out]     Buffer          A pointer to the destination buffer for the\r
+                                  data. The caller is responsible for either\r
+                                  having implicit or explicit ownership of the\r
+                                  buffer.\r
+\r
+  @retval EFI_SUCCESS             The read request was queued if Token->Event\r
+                                  is not NULL. The data was read correctly from\r
+                                  the device if the Token->Event is NULL.\r
+  @retval EFI_DEVICE_ERROR        The device reported an error while attempting\r
+                                  to perform the read operation.\r
+  @retval EFI_NO_MEDIA            There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED       The MediaId is not for the current media.\r
+  @retval EFI_BAD_BUFFER_SIZE     The BufferSize parameter is not a multiple of\r
+                                  the intrinsic block size of the device.\r
+  @retval EFI_INVALID_PARAMETER   The read request contains LBAs that are not\r
+                                  valid, or the buffer is not on proper\r
+                                  alignment.\r
+  @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a\r
+                                  lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RamDiskBlkIo2ReadBlocksEx (\r
+  IN     EFI_BLOCK_IO2_PROTOCOL   *This,\r
+  IN     UINT32                   MediaId,\r
+  IN     EFI_LBA                  Lba,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN      *Token,\r
+  IN     UINTN                    BufferSize,\r
+     OUT VOID                     *Buffer\r
+  );\r
+\r
+/**\r
+  Writes a specified number of blocks to the device.\r
+\r
+  @param[in]      This            Indicates a pointer to the calling context.\r
+  @param[in]      MediaId         The media ID that the write request is for.\r
+  @param[in]      Lba             The starting logical block address to be\r
+                                  written. The caller is responsible for\r
+                                  writing to only legitimate locations.\r
+  @param[in, out] Token           A pointer to the token associated with the\r
+                                  transaction.\r
+  @param[in]      BufferSize      The size in bytes of Buffer. This must be a\r
+                                  multiple of the intrinsic block size of the\r
+                                  device.\r
+  @param[in]      Buffer          A pointer to the source buffer for the data.\r
+\r
+  @retval EFI_SUCCESS             The write request was queued if Event is not\r
+                                  NULL. The data was written correctly to the\r
+                                  device if the Event is NULL.\r
+  @retval EFI_WRITE_PROTECTED     The device cannot be written to.\r
+  @retval EFI_NO_MEDIA            There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED       The MediaId is not for the current media.\r
+  @retval EFI_DEVICE_ERROR        The device reported an error while attempting\r
+                                  to perform the write operation.\r
+  @retval EFI_BAD_BUFFER_SIZE     The BufferSize parameter is not a multiple of\r
+                                  the intrinsic block size of the device.\r
+  @retval EFI_INVALID_PARAMETER   The write request contains LBAs that are not\r
+                                  valid, or the buffer is not on proper\r
+                                  alignment.\r
+  @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a\r
+                                  lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RamDiskBlkIo2WriteBlocksEx (\r
+  IN     EFI_BLOCK_IO2_PROTOCOL   *This,\r
+  IN     UINT32                   MediaId,\r
+  IN     EFI_LBA                  Lba,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN      *Token,\r
+  IN     UINTN                    BufferSize,\r
+  IN     VOID                     *Buffer\r
+  );\r
+\r
+/**\r
+  Flushes all modified data to a physical block device.\r
+\r
+  @param[in]      This            Indicates a pointer to the calling context.\r
+  @param[in, out] Token           A pointer to the token associated with the\r
+                                  transaction.\r
+\r
+  @retval EFI_SUCCESS             The flush request was queued if Event is not\r
+                                  NULL. All outstanding data was written\r
+                                  correctly to the device if the Event is NULL.\r
+  @retval EFI_DEVICE_ERROR        The device reported an error while attempting\r
+                                  to write data.\r
+  @retval EFI_WRITE_PROTECTED     The device cannot be written to.\r
+  @retval EFI_NO_MEDIA            There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED       The MediaId is not for the current media.\r
+  @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a\r
+                                  lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RamDiskBlkIo2FlushBlocksEx (\r
+  IN     EFI_BLOCK_IO2_PROTOCOL   *This,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN      *Token\r
+  );\r
+\r
 /**\r
   This function publish the RAM disk configuration Form.\r
 \r
index 9fe888eb9b965587a086609b5fe97d35b3d1c33b..cfeae218e76a21f093cfc025e615f0597e8ae231 100644 (file)
@@ -192,13 +192,15 @@ RamDiskRegister (
   RamDiskInitBlockIo (PrivateData);\r
 \r
   //\r
-  // Install EFI_DEVICE_PATH_PROTOCOL & EFI_BLOCK_IO_PROTOCOL on a new\r
+  // Install EFI_DEVICE_PATH_PROTOCOL & EFI_BLOCK_IO(2)_PROTOCOL on a new\r
   // handle\r
   //\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &PrivateData->Handle,\r
                   &gEfiBlockIoProtocolGuid,\r
                   &PrivateData->BlockIo,\r
+                  &gEfiBlockIo2ProtocolGuid,\r
+                  &PrivateData->BlockIo2,\r
                   &gEfiDevicePathProtocolGuid,\r
                   PrivateData->DevicePath,\r
                   NULL\r
@@ -313,12 +315,14 @@ RamDiskUnregister (
           (EndingAddr == PrivateData->StartingAddr + PrivateData->Size) &&\r
           (CompareGuid (&RamDiskDevNode->TypeGuid, &PrivateData->TypeGuid))) {\r
         //\r
-        // Uninstall the EFI_DEVICE_PATH_PROTOCOL & EFI_BLOCK_IO_PROTOCOL\r
+        // Uninstall the EFI_DEVICE_PATH_PROTOCOL & EFI_BLOCK_IO(2)_PROTOCOL\r
         //\r
         gBS->UninstallMultipleProtocolInterfaces (\r
                PrivateData->Handle,\r
                &gEfiBlockIoProtocolGuid,\r
                &PrivateData->BlockIo,\r
+               &gEfiBlockIo2ProtocolGuid,\r
+               &PrivateData->BlockIo2,\r
                &gEfiDevicePathProtocolGuid,\r
                DevicePath,\r
                NULL\r