]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/DiskIo/Dxe/diskio.c
added PPI and Protocol definitions needed by porting modules
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / DiskIo / Dxe / diskio.c
index 07d5d1ee7b72e58dd2062709a9a49dba9f6d2db7..d5efd634cfe3ae03ecb04de096a555f5c8cc29bc 100644 (file)
@@ -1,34 +1,24 @@
-/*++\r
-\r
-Copyright (c) 2006, 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
-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
-\r
-Module Name:\r
-\r
-  DiskIo.c\r
-\r
-Abstract:\r
-\r
+/** @file\r
   DiskIo driver that layers it's self on every Block IO protocol in the system.\r
   DiskIo converts a block oriented device to a byte oriented device.\r
 \r
   ReadDisk may have to do reads that are not aligned on sector boundaries.\r
   There are three cases:\r
-\r
     UnderRun - The first byte is not on a sector boundary or the read request is\r
                less than a sector in length.\r
-\r
     Aligned  - A read of N contiguous sectors.\r
-\r
     OverRun  - The last byte is not on a sector boundary.\r
 \r
---*/\r
+  Copyright (c) 2006 - 2007, 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
+  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
+\r
+**/\r
 \r
 //\r
 // Include common header file for this module.\r
@@ -56,6 +46,20 @@ DISK_IO_PRIVATE_DATA        gDiskIoPrivateDataTemplate = {
   NULL\r
 };\r
 \r
+\r
+/**\r
+  Test to see if this driver supports ControllerHandle. \r
+\r
+  @param  This                Protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test\r
+  @param  RemainingDevicePath Optional parameter use to pick a specific child\r
+                              device to start.\r
+\r
+  @retval EFI_SUCCESS         This driver supports this device\r
+  @retval EFI_ALREADY_STARTED This driver is already running on this device\r
+  @retval other               This driver does not support this device\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 DiskIoDriverBindingSupported (\r
@@ -63,23 +67,6 @@ DiskIoDriverBindingSupported (
   IN EFI_HANDLE                   ControllerHandle,\r
   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
-    than contains a BlockIo protocol can be supported.\r
-\r
-  Arguments:\r
-    This                - Protocol instance pointer.\r
-    ControllerHandle    - Handle of device to test.\r
-    RemainingDevicePath - Not used.\r
-\r
-  Returns:\r
-    EFI_SUCCESS         - This driver supports this device.\r
-    EFI_ALREADY_STARTED - This driver is already running on this device.\r
-    other               - This driver does not support this device.\r
-\r
---*/\r
 {\r
   EFI_STATUS            Status;\r
   EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
@@ -98,6 +85,7 @@ DiskIoDriverBindingSupported (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
   //\r
   // Close the I/O Abstraction(s) used to perform the supported test.\r
   //\r
@@ -110,6 +98,21 @@ DiskIoDriverBindingSupported (
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  Start this driver on ControllerHandle by opening a Block IO protocol and\r
+  installing a Disk IO protocol on ControllerHandle.\r
+\r
+  @param  This                 Protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               device to start.\r
+\r
+  @retval EFI_SUCCESS          This driver is added to ControllerHandle\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle\r
+  @retval other                This driver does not support this device\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 DiskIoDriverBindingStart (\r
@@ -117,23 +120,6 @@ DiskIoDriverBindingStart (
   IN EFI_HANDLE                   ControllerHandle,\r
   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Start this driver on ControllerHandle by opening a Block IO protocol and\r
-    installing a Disk IO protocol on ControllerHandle.\r
-\r
-  Arguments:\r
-    This                - Protocol instance pointer.\r
-    ControllerHandle    - Handle of device to bind driver to.\r
-    RemainingDevicePath - Not used, always produce all possible children.\r
-\r
-  Returns:\r
-    EFI_SUCCESS         - This driver is added to ControllerHandle.\r
-    EFI_ALREADY_STARTED - This driver is already running on ControllerHandle.\r
-    other               - This driver does not support this device.\r
-\r
---*/\r
 {\r
   EFI_STATUS            Status;\r
   DISK_IO_PRIVATE_DATA  *Private;\r
@@ -154,6 +140,7 @@ DiskIoDriverBindingStart (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+  \r
   //\r
   // Initialize the Disk IO device instance.\r
   //\r
@@ -162,6 +149,7 @@ DiskIoDriverBindingStart (
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ErrorExit;\r
   }\r
+  \r
   //\r
   // Install protocol interfaces for the Disk IO device.\r
   //\r
@@ -190,6 +178,21 @@ ErrorExit:
   return Status;\r
 }\r
 \r
+\r
+/**\r
+  Stop this driver on ControllerHandle by removing Disk IO protocol and closing\r
+  the Block IO protocol on ControllerHandle.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
+  @retval other             This driver was not removed from this device\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 DiskIoDriverBindingStop (\r
@@ -198,24 +201,6 @@ DiskIoDriverBindingStop (
   IN  UINTN                          NumberOfChildren,\r
   IN  EFI_HANDLE                     *ChildHandleBuffer\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Stop this driver on ControllerHandle by removing Disk IO protocol and closing\r
-    the Block IO protocol on ControllerHandle.\r
-\r
-  Arguments:\r
-    This              - Protocol instance pointer.\r
-    ControllerHandle  - Handle of device to stop driver on.\r
-    NumberOfChildren  - Not used.\r
-    ChildHandleBuffer - Not used.\r
-\r
-  Returns:\r
-    EFI_SUCCESS         - This driver is removed ControllerHandle.\r
-    other               - This driver was not removed from this device.\r
-    EFI_UNSUPPORTED\r
-\r
---*/\r
 {\r
   EFI_STATUS            Status;\r
   EFI_DISK_IO_PROTOCOL  *DiskIo;\r
@@ -260,6 +245,31 @@ DiskIoDriverBindingStop (
   return Status;\r
 }\r
 \r
+\r
+\r
+/**\r
+  Read BufferSize bytes from Offset into Buffer.\r
+  Reads may support reads that are not aligned on\r
+  sector boundaries. There are three cases:\r
+    UnderRun - The first byte is not on a sector boundary or the read request is\r
+               less than a sector in length.\r
+    Aligned  - A read of N contiguous sectors.\r
+    OverRun  - The last byte is not on a sector boundary.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  MediaId               Id of the media, changes every time the media is replaced.\r
+  @param  Offset                The starting byte offset to read from\r
+  @param  BufferSize            Size of Buffer\r
+  @param  Buffer                Buffer containing read 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 performing the read.\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_INVALID_PARAMETER The read request contains device addresses that are not\r
+                                valid for the device.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 DiskIoReadDisk (\r
@@ -269,39 +279,6 @@ DiskIoReadDisk (
   IN UINTN                 BufferSize,\r
   OUT VOID                 *Buffer\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Read BufferSize bytes from Offset into Buffer.\r
-\r
-    Reads may support reads that are not aligned on\r
-    sector boundaries. There are three cases:\r
-\r
-      UnderRun - The first byte is not on a sector boundary or the read request is\r
-                 less than a sector in length.\r
-\r
-      Aligned  - A read of N contiguous sectors.\r
-\r
-      OverRun  - The last byte is not on a sector boundary.\r
-\r
-\r
-  Arguments:\r
-    This       - Protocol instance pointer.\r
-    MediaId    - Id of the media, changes every time the media is replaced.\r
-    Offset     - The starting byte offset to read from.\r
-    BufferSize - Size of Buffer.\r
-    Buffer     - Buffer containing read data.\r
-\r
-  Returns:\r
-    EFI_SUCCESS           - The data was read correctly from the device.\r
-    EFI_DEVICE_ERROR      - The device reported an error while performing the read.\r
-    EFI_NO_MEDIA          - There is no media in the device.\r
-    EFI_MEDIA_CHNAGED     - The MediaId does not matched the current device.\r
-    EFI_INVALID_PARAMETER - The read request contains device addresses that are not\r
-                            valid for the device.\r
-    EFI_OUT_OF_RESOURCES\r
-\r
---*/\r
 {\r
   EFI_STATUS            Status;\r
   DISK_IO_PRIVATE_DATA  *Private;\r
@@ -485,6 +462,32 @@ Done:
   return Status;\r
 }\r
 \r
+\r
+/**\r
+  Read BufferSize bytes from Offset into Buffer.\r
+  Writes may require a read modify write to support writes that are not\r
+  aligned on sector boundaries. There are three cases:\r
+    UnderRun - The first byte is not on a sector boundary or the write request\r
+               is less than a sector in length. Read modify write is required.\r
+    Aligned  - A write of N contiguous sectors.\r
+    OverRun  - The last byte is not on a sector boundary. Read modified write\r
+               required.\r
+\r
+  @param  This       Protocol instance pointer.\r
+  @param  MediaId    Id of the media, changes every time the media is replaced.\r
+  @param  Offset     The starting byte offset to read from\r
+  @param  BufferSize Size of Buffer\r
+  @param  Buffer     Buffer containing read 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_INVALID_PARAMETER The write request contains device addresses that are not\r
+                                 valid for the device.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 DiskIoWriteDisk (\r
@@ -494,40 +497,6 @@ DiskIoWriteDisk (
   IN UINTN                 BufferSize,\r
   IN VOID                  *Buffer\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Read BufferSize bytes from Offset into Buffer.\r
-\r
-    Writes may require a read modify write to support writes that are not\r
-    aligned on sector boundaries. There are three cases:\r
-\r
-      UnderRun - The first byte is not on a sector boundary or the write request\r
-                 is less than a sector in length. Read modify write is required.\r
-\r
-      Aligned  - A write of N contiguous sectors.\r
-\r
-      OverRun  - The last byte is not on a sector boundary. Read modified write\r
-                 required.\r
-\r
-  Arguments:\r
-    This       - Protocol instance pointer.\r
-    MediaId    - Id of the media, changes every time the media is replaced.\r
-    Offset     - The starting byte offset to read from.\r
-    BufferSize - Size of Buffer.\r
-    Buffer     - Buffer containing read data.\r
-\r
-  Returns:\r
-    EFI_SUCCESS           - The data was written correctly to the device.\r
-    EFI_WRITE_PROTECTED   - The device can not be written to.\r
-    EFI_DEVICE_ERROR      - The device reported an error while performing the write.\r
-    EFI_NO_MEDIA          - There is no media in the device.\r
-    EFI_MEDIA_CHNAGED     - The MediaId does not matched the current device.\r
-    EFI_INVALID_PARAMETER - The write request contains device addresses that are not\r
-                            valid for the device.\r
-    EFI_OUT_OF_RESOURCES\r
-\r
---*/\r
 {\r
   EFI_STATUS            Status;\r
   DISK_IO_PRIVATE_DATA  *Private;\r
@@ -732,3 +701,42 @@ Done:
 \r
   return Status;\r
 }\r
+\r
+\r
+/**\r
+  The user Entry Point for module DiskIo. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeDiskIo (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gDiskIoDriverBinding,\r
+             ImageHandle,\r
+             &gDiskIoComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r