]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Isa/IsaFloppyDxe/IsaFloppyBlock.c
Isa Floppy driver code scrub.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaFloppyDxe / IsaFloppyBlock.c
index 5f4a9903574c473a94519da7b678466ba38ce17f..b823034bc5124ceaba6c882de45a7c4e265f9032 100644 (file)
@@ -1,15 +1,7 @@
-/**@file\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
+/** @file \r
+  Implementation of the EFI Block IO Protocol for ISA Floppy driver\r
   \r
-  Implement the Block IO interface\r
-  \r
-Copyright (c) 2006 - 2007, Intel Corporation.<BR>\r
+Copyright (c) 2006 - 2009, 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
@@ -20,20 +12,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-\r
 #include "IsaFloppy.h"\r
 \r
 /**\r
-  Reset the Floppy Logic Drive, call the FddReset function   \r
-  \r
-  @param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface\r
-  @param 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
-  @retval  EFI_SUCCESS:      The Floppy Logic Drive is reset\r
-  @retval  EFI_DEVICE_ERROR: The Floppy Logic Drive is not functioning correctly \r
-                      and can not be reset\r
+  Reset the Block Device.\r
+\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
@@ -59,10 +48,13 @@ FdcReset (
 }\r
 \r
 /**\r
-  Flush block via fdd controller\r
-  \r
-  @param  This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface\r
-  @return EFI_SUCCESS\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
@@ -78,10 +70,10 @@ FddFlushBlocks (
 }\r
 \r
 /**\r
-  Common report status code interface\r
+  Common report status code interface.\r
   \r
   @param This  Pointer of FDC_BLK_IO_DEV instance\r
-  @param Read  Error type: read or write?\r
+  @param Read  Read or write operation when error occurrs\r
 **/\r
 VOID\r
 FddReportStatus (\r
@@ -101,23 +93,22 @@ FddReportStatus (
 }\r
 \r
 /**\r
-  Read the requested number of blocks from the device   \r
-  \r
-  @param This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface\r
-  @param MediaId UINT32:    The media id that the read request is for    \r
-  @param  LBA EFI_LBA:     The starting logic block address to read from on the device\r
-  @param  BufferSize UINTN:  The size of the Buffer in bytes\r
-  @param  Buffer VOID *:     A pointer to the destination buffer for the data\r
-  \r
-  @retval  EFI_SUCCESS:     The data was read correctly from the device\r
-  @retval  EFI_DEVICE_ERROR:The device reported an error while attempting to perform\r
-                     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 the \r
-                         intrinsic 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
+  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
@@ -125,14 +116,14 @@ EFIAPI
 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
   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
@@ -142,38 +133,38 @@ FddReadBlocks (
 }\r
 \r
 /**\r
-  Write a specified number of blocks to the device   \r
-  \r
-  @param  This EFI_BLOCK_IO *: A pointer to the Block I/O protocol interface\r
-  @param  MediaId UINT32:    The media id that the write request is for   \r
-  @param  LBA EFI_LBA:     The starting logic block address to be written\r
-  @param  BufferSize UINTN:  The size in bytes in Buffer\r
-  @param  Buffer VOID *:     A pointer to the source buffer for the data\r
-  \r
-  @retval  EFI_SUCCESS:     The data were written correctly to the device\r
-  @retval  EFI_WRITE_PROTECTED: The device can not 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 to perform \r
-                       the write operation \r
-  @retval  EFI_BAD_BUFFER_SIZE: The BufferSize parameter is not a multiple of the \r
-                         intrinsic 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
+  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
   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
@@ -183,36 +174,31 @@ FddWriteBlocks (
 }\r
 \r
 /**\r
-  Read or Write a number of blocks to floppy device\r
-\r
-  @param This     Pointer to instance of EFI_BLOCK_IO_PROTOCOL\r
-  @param MediaId  The media id of read/write request\r
-  @param LBA      The starting logic block address to read from on the device\r
-  @param BufferSize The size of the Buffer in bytes\r
-  @param Operation   - GC_TODO: add argument description\r
-  @param Buffer      - GC_TODO: add argument description\r
-\r
-  @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value\r
-  @retval EFI_SUCCESS - GC_TODO: Add description for return value\r
-  @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
-  @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
-  @retval EFI_NO_MEDIA - GC_TODO: Add description for return value\r
-  @retval EFI_MEDIA_CHANGED - GC_TODO: Add description for return value\r
-  @retval EFI_WRITE_PROTECTED - GC_TODO: Add description for return value\r
-  @retval EFI_BAD_BUFFER_SIZE - GC_TODO: Add description for return value\r
-  @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value\r
-  @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value\r
-  @retval EFI_SUCCESS - GC_TODO: Add description for return value\r
-  @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
-  @retval EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
-  @retval EFI_SUCCESS - GC_TODO: Add description for return value\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
@@ -224,10 +210,7 @@ FddReadWriteBlocks (
   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
@@ -238,7 +221,7 @@ FddReadWriteBlocks (
   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
@@ -274,13 +257,6 @@ FddReadWriteBlocks (
   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
@@ -306,12 +282,12 @@ FddReadWriteBlocks (
     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
@@ -320,8 +296,8 @@ FddReadWriteBlocks (
     //\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
@@ -338,26 +314,26 @@ FddReadWriteBlocks (
   }\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
@@ -371,7 +347,7 @@ FddReadWriteBlocks (
     //\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
@@ -381,18 +357,18 @@ FddReadWriteBlocks (
 }\r
 \r
 /**\r
-  Common interface for free cache \r
+  Free cache for a floppy disk.\r
   \r
-  @param FdcDev  Pointer of FDC_BLK_IO_DEV instance\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
-  if (FdcDev->Cache) {\r
-    gBS->FreePool (FdcDev->Cache);\r
+  if (FdcDev->Cache != NULL) {\r
+    FreePool (FdcDev->Cache);\r
     FdcDev->Cache = NULL;\r
   }\r
 }\r