]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Isa/IsaFloppyDxe/IsaFloppyBlock.c
IntelFrameworkModulePkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaFloppyDxe / IsaFloppyBlock.c
index e6282ca5e105c39c1903d17044d638145f0c60bb..2dce7ac7e0b717568195ee5cbd6bef4e40c2425d 100644 (file)
@@ -1,59 +1,35 @@
-/*++\r
+/** @file\r
+  Implementation of the EFI Block IO Protocol for ISA Floppy driver\r
 \r
-  Copyright (c) 2006 - 2007, Intel Corporation<BR>\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
-  http://opensource.org/licenses/bsd-license.php\r
+Copyright (c) 2006 - 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
+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
 \r
-Module Name:\r
+**/\r
 \r
-  IsaFloppyBlock.c\r
-\r
-Abstract:\r
-\r
-  ISA Floppy Driver\r
-  1. Support two types diskette drive  \r
-     1.44M drive and 2.88M drive (and now only support 1.44M)\r
-  2. Support two diskette drives\r
-  3. Use DMA channel 2 to transfer data\r
-  4. Do not use interrupt\r
-  5. Support diskette change line signal and write protect\r
-  \r
-  Implement the Block IO interface\r
-\r
-Revision History:\r
+#include "IsaFloppy.h"\r
 \r
---*/\r
+/**\r
+  Reset the Block Device.\r
 \r
-#include "IsaFloppy.h"\r
+  @param  This                 Indicates a pointer to the calling context.\r
+  @param  ExtendedVerification Driver may perform diagnostics on reset.\r
 \r
+  @retval EFI_SUCCESS          The device was reset.\r
+  @retval EFI_DEVICE_ERROR     The device is not functioning properly and could\r
+                               not be reset.\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FdcReset (\r
   IN  EFI_BLOCK_IO_PROTOCOL  *This,\r
   IN  BOOLEAN                ExtendedVerification\r
   )\r
-/*++\r
-  \r
-  Routine Description:  Reset the Floppy Logic Drive, call the FddReset function   \r
-  Parameters:\r
-    This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface\r
-    ExtendedVerification BOOLEAN: Indicate that the driver may perform a more \r
-                    exhaustive verification operation of the device during \r
-                    reset, now this par is ignored in this driver          \r
-  Returns:\r
-    EFI_SUCCESS:      The Floppy Logic Drive is reset\r
-    EFI_DEVICE_ERROR: The Floppy Logic Drive is not functioning correctly \r
-                      and can not be reset\r
-\r
---*/\r
-// GC_TODO: function comment is missing 'Arguments:'\r
-// GC_TODO:    This - add argument and description to function comment\r
-// GC_TODO:    ExtendedVerification - add argument and description to function comment\r
 {\r
   FDC_BLK_IO_DEV  *FdcDev;\r
 \r
@@ -71,22 +47,21 @@ FdcReset (
   return FddReset (FdcDev);\r
 }\r
 \r
+/**\r
+  Flush the Block Device.\r
+\r
+  @param  This              Indicates a pointer to the calling context.\r
+\r
+  @retval EFI_SUCCESS       All outstanding data was written to the device\r
+  @retval EFI_DEVICE_ERROR  The device reported an error while writting back the data\r
+  @retval EFI_NO_MEDIA      There is no media in the device.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FddFlushBlocks (\r
   IN  EFI_BLOCK_IO_PROTOCOL  *This\r
   )\r
-/*++\r
-  \r
-  Routine Description:  \r
-  Parameters:\r
-    This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface\r
-  Returns:\r
-    EFI_SUCCESS:    \r
-\r
---*/\r
-// GC_TODO: function comment is missing 'Arguments:'\r
-// GC_TODO:    This - add argument and description to function comment\r
 {\r
   //\r
   // Not supported yet\r
@@ -94,28 +69,17 @@ FddFlushBlocks (
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
+/**\r
+  Common report status code interface.\r
+\r
+  @param This  Pointer of FDC_BLK_IO_DEV instance\r
+  @param Read  Read or write operation when error occurrs\r
+**/\r
 VOID\r
 FddReportStatus (\r
   IN  EFI_BLOCK_IO_PROTOCOL  *This,\r
   IN  BOOLEAN                Read\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  This  - GC_TODO: add argument description\r
-  Read  - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  GC_TODO: add return values\r
-\r
---*/\r
 {\r
   FDC_BLK_IO_DEV  *FdcDev;\r
 \r
@@ -128,46 +92,38 @@ Returns:
     );\r
 }\r
 \r
+/**\r
+  Read BufferSize bytes from Lba into Buffer.\r
+\r
+  @param  This       Indicates a pointer to the calling context.\r
+  @param  MediaId    Id of the media, changes every time the media is replaced.\r
+  @param  Lba        The starting Logical Block Address to read from\r
+  @param  BufferSize Size of Buffer, must be a multiple of device block size.\r
+  @param  Buffer     A pointer to the destination buffer for the data. The caller is\r
+                     responsible for either having implicit or explicit ownership of the buffer.\r
+\r
+  @retval EFI_SUCCESS           The data was read correctly from the device.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.\r
+  @retval EFI_NO_MEDIA          There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.\r
+  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
+  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
+                                or the buffer is not on proper alignment.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FddReadBlocks (\r
   IN  EFI_BLOCK_IO_PROTOCOL  *This,\r
   IN  UINT32                 MediaId,\r
-  IN  EFI_LBA                LBA,\r
+  IN  EFI_LBA                Lba,\r
   IN  UINTN                  BufferSize,\r
   OUT VOID                   *Buffer\r
   )\r
-/*++\r
-\r
-  Routine Description:  Read the requested number of blocks from the device   \r
-  Parameters:\r
-    This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface\r
-    MediaId UINT32:    The media id that the read request is for    \r
-    LBA EFI_LBA:     The starting logic block address to read from on the device\r
-    BufferSize UINTN:  The size of the Buffer in bytes\r
-    Buffer VOID *:     A pointer to the destination buffer for the data\r
-  Returns:\r
-    EFI_SUCCESS:     The data was read correctly from the device\r
-    EFI_DEVICE_ERROR:The device reported an error while attempting to perform\r
-                     the read operation\r
-    EFI_NO_MEDIA:    There is no media in the device\r
-    EFI_MEDIA_CHANGED:   The MediaId is not for the current media\r
-    EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the \r
-                         intrinsic block size of the device\r
-    EFI_INVALID_PARAMETER:The read request contains LBAs that are not valid, \r
-                          or the buffer is not on proper alignment \r
-\r
---*/\r
-// GC_TODO: function comment is missing 'Arguments:'\r
-// GC_TODO:    This - add argument and description to function comment\r
-// GC_TODO:    MediaId - add argument and description to function comment\r
-// GC_TODO:    LBA - add argument and description to function comment\r
-// GC_TODO:    BufferSize - add argument and description to function comment\r
-// GC_TODO:    Buffer - add argument and description to function comment\r
 {\r
   EFI_STATUS  Status;\r
 \r
-  Status = FddReadWriteBlocks (This, MediaId, LBA, BufferSize, READ, Buffer);\r
+  Status = FddReadWriteBlocks (This, MediaId, Lba, BufferSize, READ, Buffer);\r
 \r
   if (EFI_ERROR (Status)) {\r
     FddReportStatus (This, TRUE);\r
@@ -176,48 +132,39 @@ FddReadBlocks (
   return Status;\r
 }\r
 \r
+/**\r
+  Write BufferSize bytes from Lba into Buffer.\r
+\r
+  @param  This       Indicates a pointer to the calling context.\r
+  @param  MediaId    The media ID that the write request is for.\r
+  @param  Lba        The starting logical block address to be written. The caller is\r
+                     responsible for writing to only legitimate locations.\r
+  @param  BufferSize Size of Buffer, must be a multiple of device block size.\r
+  @param  Buffer     A pointer to the source buffer for the data.\r
+\r
+  @retval EFI_SUCCESS           The data was written correctly to the device.\r
+  @retval EFI_WRITE_PROTECTED   The device can not be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
+  @retval EFI_NO_MEDIA          There is no media in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.\r
+  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
+  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r
+                                or the buffer is not on proper alignment.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FddWriteBlocks (\r
   IN EFI_BLOCK_IO_PROTOCOL  *This,\r
   IN UINT32                 MediaId,\r
-  IN EFI_LBA                LBA,\r
+  IN EFI_LBA                Lba,\r
   IN UINTN                  BufferSize,\r
   IN VOID                   *Buffer\r
   )\r
-/*++\r
-\r
-  Routine Description:  Write a specified number of blocks to the device   \r
-  Parameters:\r
-    This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface\r
-    MediaId UINT32:    The media id that the write request is for   \r
-    LBA EFI_LBA:     The starting logic block address to be written\r
-    BufferSize UINTN:  The size in bytes in Buffer\r
-    Buffer VOID *:     A pointer to the source buffer for the data\r
-  Returns :\r
-    EFI_SUCCESS:     The data were written correctly to the device\r
-    EFI_WRITE_PROTECTED: The device can not be written to \r
-    EFI_NO_MEDIA:    There is no media in the device\r
-    EFI_MEDIA_CHANGED:   The MediaId is not for the current media\r
-    EFI_DEVICE_ERROR:  The device reported an error while attempting to perform \r
-                       the write operation \r
-    EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the \r
-                         intrinsic block size of the device\r
-    EFI_INVALID_PARAMETER:The write request contains LBAs that are not valid, \r
-                          or the buffer is not on proper alignment \r
-\r
---*/\r
-// GC_TODO: function comment is missing 'Arguments:'\r
-// GC_TODO: function comment is missing 'Returns:'\r
-// GC_TODO:    This - add argument and description to function comment\r
-// GC_TODO:    MediaId - add argument and description to function comment\r
-// GC_TODO:    LBA - add argument and description to function comment\r
-// GC_TODO:    BufferSize - add argument and description to function comment\r
-// GC_TODO:    Buffer - add argument and description to function comment\r
 {\r
   EFI_STATUS  Status;\r
 \r
-  Status = FddReadWriteBlocks (This, MediaId, LBA, BufferSize, WRITE, Buffer);\r
+  Status = FddReadWriteBlocks (This, MediaId, Lba, BufferSize, WRITE, Buffer);\r
 \r
   if (EFI_ERROR (Status)) {\r
     FddReportStatus (This, FALSE);\r
@@ -226,48 +173,36 @@ FddWriteBlocks (
   return Status;\r
 }\r
 \r
+/**\r
+  Read or Write a number of blocks to floppy disk\r
+\r
+  @param  This       Indicates a pointer to the calling context.\r
+  @param  MediaId    Id of the media, changes every time the media is replaced.\r
+  @param  Lba        The starting Logical Block Address to read from\r
+  @param  BufferSize Size of Buffer, must be a multiple of device block size.\r
+  @param  Operation  Specifies the read or write operation.\r
+  @param  Buffer     A pointer to the destination buffer for the data. The caller is\r
+                     responsible for either having implicit or explicit ownership of the buffer.\r
+\r
+  @retval EFI_SUCCESS           The data was read correctly from the device.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.\r
+  @retval EFI_NO_MEDIA          There is no media in the device.\r
+  @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.\r
+  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
+  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
+                                or the buffer is not on proper alignment.\r
+  @retval EFI_WRITE_PROTECTED   The device can not be written to.\r
+\r
+**/\r
 EFI_STATUS\r
 FddReadWriteBlocks (\r
   IN  EFI_BLOCK_IO_PROTOCOL  *This,\r
   IN  UINT32                 MediaId,\r
-  IN  EFI_LBA                LBA,\r
+  IN  EFI_LBA                Lba,\r
   IN  UINTN                  BufferSize,\r
   IN  BOOLEAN                Operation,\r
   OUT VOID                   *Buffer\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  This        - GC_TODO: add argument description\r
-  MediaId     - GC_TODO: add argument description\r
-  LBA         - GC_TODO: add argument description\r
-  BufferSize  - GC_TODO: add argument description\r
-  Operation   - GC_TODO: add argument description\r
-  Buffer      - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  EFI_INVALID_PARAMETER - GC_TODO: Add description for return value\r
-  EFI_SUCCESS - GC_TODO: Add description for return value\r
-  EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
-  EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
-  EFI_NO_MEDIA - GC_TODO: Add description for return value\r
-  EFI_MEDIA_CHANGED - GC_TODO: Add description for return value\r
-  EFI_WRITE_PROTECTED - GC_TODO: Add description for return value\r
-  EFI_BAD_BUFFER_SIZE - GC_TODO: Add description for return value\r
-  EFI_INVALID_PARAMETER - GC_TODO: Add description for return value\r
-  EFI_INVALID_PARAMETER - GC_TODO: Add description for return value\r
-  EFI_SUCCESS - GC_TODO: Add description for return value\r
-  EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
-  EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
-  EFI_SUCCESS - GC_TODO: Add description for return value\r
-\r
---*/\r
 {\r
   EFI_BLOCK_IO_MEDIA  *Media;\r
   FDC_BLK_IO_DEV      *FdcDev;\r
@@ -275,10 +210,7 @@ Returns:
   UINTN               NumberOfBlocks;\r
   UINTN               BlockCount;\r
   EFI_STATUS          Status;\r
-  //\r
-  //  EFI_STATUS            CacheStatus;\r
-  //\r
-  EFI_LBA             LBA0;\r
+  EFI_LBA             Lba0;\r
   UINT8               *Pointer;\r
 \r
   //\r
@@ -289,20 +221,11 @@ Returns:
   FdcDev    = FDD_BLK_IO_FROM_THIS (This);\r
 \r
   if (Operation == WRITE) {\r
-    if (LBA == 0) {\r
+    if (Lba == 0) {\r
       FdcFreeCache (FdcDev);\r
     }\r
   }\r
-  //\r
-  // Check the Parameter is valid\r
-  //\r
-  if (Buffer == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
 \r
-  if (BufferSize == 0) {\r
-    return EFI_SUCCESS;\r
-  }\r
   //\r
   // Set the drive motor on\r
   //\r
@@ -325,13 +248,6 @@ Returns:
   if (!(Media->MediaPresent)) {\r
     MotorOff (FdcDev);\r
     FdcFreeCache (FdcDev);\r
-\r
-    /*\r
-    if (FdcDev->Cache) {\r
-      gBS->FreePool (FdcDev->Cache);\r
-      FdcDev->Cache = NULL;\r
-    }\r
-*/\r
     return EFI_NO_MEDIA;\r
   }\r
   //\r
@@ -343,6 +259,11 @@ Returns:
     return EFI_MEDIA_CHANGED;\r
   }\r
 \r
+  if (BufferSize == 0) {\r
+    MotorOff (FdcDev);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   if (Operation == WRITE) {\r
     if (Media->ReadOnly) {\r
       MotorOff (FdcDev);\r
@@ -352,17 +273,22 @@ Returns:
   //\r
   // Check the parameters for this read/write operation\r
   //\r
+  if (Buffer == NULL) {\r
+    MotorOff (FdcDev);\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   if (BufferSize % BlockSize != 0) {\r
     MotorOff (FdcDev);\r
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
 \r
-  if (LBA > Media->LastBlock) {\r
+  if (Lba > Media->LastBlock) {\r
     MotorOff (FdcDev);\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (((BufferSize / BlockSize) + LBA - 1) > Media->LastBlock) {\r
+  if (((BufferSize / BlockSize) + Lba - 1) > Media->LastBlock) {\r
     MotorOff (FdcDev);\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -371,8 +297,8 @@ Returns:
     //\r
     // See if the data that is being read is already in the cache\r
     //\r
-    if (FdcDev->Cache) {\r
-      if (LBA == 0 && BufferSize == BlockSize) {\r
+    if (FdcDev->Cache != NULL) {\r
+      if (Lba == 0 && BufferSize == BlockSize) {\r
         MotorOff (FdcDev);\r
         CopyMem ((UINT8 *) Buffer, (UINT8 *) FdcDev->Cache, BlockSize);\r
         return EFI_SUCCESS;\r
@@ -389,26 +315,26 @@ Returns:
   }\r
 \r
   NumberOfBlocks  = BufferSize / BlockSize;\r
-  LBA0            = LBA;\r
+  Lba0            = Lba;\r
   Pointer         = Buffer;\r
 \r
   //\r
   // read blocks in the same cylinder.\r
   // in a cylinder , there are 18 * 2 = 36 blocks\r
   //\r
-  BlockCount = GetTransferBlockCount (FdcDev, LBA, NumberOfBlocks);\r
+  BlockCount = GetTransferBlockCount (FdcDev, Lba, NumberOfBlocks);\r
   while ((BlockCount != 0) && !EFI_ERROR (Status)) {\r
-    Status = ReadWriteDataSector (FdcDev, Buffer, LBA, BlockCount, Operation);\r
+    Status = ReadWriteDataSector (FdcDev, Buffer, Lba, BlockCount, Operation);\r
     if (EFI_ERROR (Status)) {\r
       MotorOff (FdcDev);\r
       FddReset (FdcDev);\r
       return EFI_DEVICE_ERROR;\r
     }\r
 \r
-    LBA += BlockCount;\r
+    Lba += BlockCount;\r
     NumberOfBlocks -= BlockCount;\r
     Buffer      = (VOID *) ((UINTN) Buffer + BlockCount * BlockSize);\r
-    BlockCount  = GetTransferBlockCount (FdcDev, LBA, NumberOfBlocks);\r
+    BlockCount  = GetTransferBlockCount (FdcDev, Lba, NumberOfBlocks);\r
   }\r
 \r
   Buffer = Pointer;\r
@@ -422,7 +348,7 @@ Returns:
     //\r
     // Cache the data read\r
     //\r
-    if (LBA0 == 0 && !FdcDev->Cache) {\r
+    if (Lba0 == 0 && FdcDev->Cache == NULL) {\r
       FdcDev->Cache = AllocateCopyPool (BlockSize, Buffer);\r
     }\r
   }\r
@@ -431,28 +357,19 @@ Returns:
 \r
 }\r
 \r
+/**\r
+  Free cache for a floppy disk.\r
+\r
+  @param FdcDev  A Pointer to FDC_BLK_IO_DEV instance\r
+\r
+**/\r
 VOID\r
 FdcFreeCache (\r
-  IN    FDC_BLK_IO_DEV  *FdcDev\r
+  IN FDC_BLK_IO_DEV  *FdcDev\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  FdcDev  - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  GC_TODO: add return values\r
-\r
---*/\r
 {\r
-  if (FdcDev->Cache) {\r
-    gBS->FreePool (FdcDev->Cache);\r
+  if (FdcDev->Cache != NULL) {\r
+    FreePool (FdcDev->Cache);\r
     FdcDev->Cache = NULL;\r
   }\r
 }\r