]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.h
AtaBusDxe: Fix ReadBlockEx andWriteBlockEx to still signal event when the BufferSize...
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / DiskIoDxe / DiskIo.h
index c1a572f846bafcd5c5ae0e6bbf68d6a5e948eb78..7591e469a19b465cb22b12525d11748308d46ecb 100644 (file)
@@ -1,23 +1,24 @@
 /** @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
+  Master header file for DiskIo driver. It includes the module private defininitions.\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
+Copyright (c) 2006 - 2013, 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
 **/\r
 \r
-#ifndef _DISK_IO_H\r
-#define _DISK_IO_H\r
+#ifndef _DISK_IO_H_\r
+#define _DISK_IO_H_\r
 \r
 #include <Uefi.h>\r
 #include <Protocol/BlockIo.h>\r
+#include <Protocol/BlockIo2.h>\r
+#include <Protocol/DiskIo2.h>\r
 #include <Protocol/ComponentName.h>\r
 #include <Protocol/DriverBinding.h>\r
 #include <Protocol/DiskIo.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 \r
+#define DISK_IO_PRIVATE_DATA_SIGNATURE  SIGNATURE_32 ('d', 's', 'k', 'I')\r
+typedef struct {\r
+  UINT32                          Signature;\r
 \r
-#define DISK_IO_PRIVATE_DATA_SIGNATURE  EFI_SIGNATURE_32 ('d', 's', 'k', 'I')\r
+  EFI_DISK_IO_PROTOCOL            DiskIo;\r
+  EFI_DISK_IO2_PROTOCOL           DiskIo2;\r
+  EFI_BLOCK_IO_PROTOCOL           *BlockIo;\r
+  EFI_BLOCK_IO2_PROTOCOL          *BlockIo2;\r
 \r
-#define DATA_BUFFER_BLOCK_NUM           (64)\r
+  UINT8                           *SharedWorkingBuffer;\r
 \r
-typedef struct {\r
-  UINTN                 Signature;\r
-  EFI_DISK_IO_PROTOCOL  DiskIo;\r
-  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  EFI_LOCK                        TaskQueueLock;\r
+  LIST_ENTRY                      TaskQueue;\r
 } DISK_IO_PRIVATE_DATA;\r
+#define DISK_IO_PRIVATE_DATA_FROM_DISK_IO(a)  CR (a, DISK_IO_PRIVATE_DATA, DiskIo,  DISK_IO_PRIVATE_DATA_SIGNATURE)\r
+#define DISK_IO_PRIVATE_DATA_FROM_DISK_IO2(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo2, DISK_IO_PRIVATE_DATA_SIGNATURE)\r
+\r
+#define DISK_IO2_TASK_SIGNATURE   SIGNATURE_32 ('d', 'i', 'a', 't')\r
+typedef struct {\r
+  UINT32                          Signature;\r
+  LIST_ENTRY                      Link;     /// < link to other task\r
+  EFI_LOCK                        SubtasksLock;\r
+  LIST_ENTRY                      Subtasks; /// < header of subtasks\r
+  EFI_DISK_IO2_TOKEN              *Token;\r
+  DISK_IO_PRIVATE_DATA            *Instance;\r
+} DISK_IO2_TASK;\r
 \r
-#define DISK_IO_PRIVATE_DATA_FROM_THIS(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo, DISK_IO_PRIVATE_DATA_SIGNATURE)\r
+#define DISK_IO2_FLUSH_TASK_SIGNATURE SIGNATURE_32 ('d', 'i', 'f', 't')\r
+typedef struct {\r
+  UINT32                          Signature;\r
+  EFI_BLOCK_IO2_TOKEN             BlockIo2Token;\r
+  EFI_DISK_IO2_TOKEN              *Token;\r
+} DISK_IO2_FLUSH_TASK;\r
+\r
+#define DISK_IO_SUBTASK_SIGNATURE SIGNATURE_32 ('d', 'i', 's', 't')\r
+typedef struct {\r
+  //\r
+  // UnderRun:  Offset != 0, Length < BlockSize\r
+  // OverRun:   Offset == 0, Length < BlockSize\r
+  // Middle:    Offset is block aligned, Length is multiple of block size\r
+  //\r
+  UINT32                          Signature;\r
+  LIST_ENTRY                      Link;\r
+  BOOLEAN                         Write;\r
+  UINT64                          Lba;\r
+  UINT32                          Offset;\r
+  UINTN                           Length;\r
+  UINT8                           *WorkingBuffer; /// < NULL indicates using "Buffer" directly\r
+  UINT8                           *Buffer;\r
+  BOOLEAN                         Blocking;\r
+\r
+  //\r
+  // Following fields are for DiskIo2\r
+  //\r
+  DISK_IO2_TASK                   *Task;\r
+  EFI_BLOCK_IO2_TOKEN             BlockIo2Token;\r
+} DISK_IO_SUBTASK;\r
 \r
 //\r
 // Global Variables\r
 //\r
-extern EFI_DRIVER_BINDING_PROTOCOL  gDiskIoDriverBinding;\r
-extern EFI_COMPONENT_NAME_PROTOCOL  gDiskIoComponentName;\r
+extern EFI_DRIVER_BINDING_PROTOCOL   gDiskIoDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL   gDiskIoComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL  gDiskIoComponentName2;\r
 \r
 //\r
 // Prototypes\r
 // Driver model protocol interface\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
-  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
-  IN EFI_HANDLE                     ControllerHandle,\r
-  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\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
-  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
-  IN EFI_HANDLE                     ControllerHandle,\r
-  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\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
@@ -80,6 +168,29 @@ DiskIoDriverBindingStop (
 //\r
 // Disk I/O Protocol Interface\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
@@ -90,6 +201,31 @@ DiskIoReadDisk (
   OUT VOID                 *Buffer\r
   );\r
 \r
+/**\r
+  Writes BufferSize bytes from Buffer into Offset.\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
@@ -100,9 +236,152 @@ DiskIoWriteDisk (
   IN VOID                  *Buffer\r
   );\r
 \r
+\r
+/**\r
+  Terminate outstanding asynchronous requests to a device.\r
+\r
+  @param This                   Indicates a pointer to the calling context.\r
+\r
+  @retval EFI_SUCCESS           All outstanding requests were successfully terminated.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the cancel\r
+                                operation.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2Cancel (\r
+  IN EFI_DISK_IO2_PROTOCOL *This\r
+  );\r
+\r
+/**\r
+  Reads a specified number of bytes from a device.\r
+\r
+  @param This                   Indicates a pointer to the calling context.\r
+  @param MediaId                ID of the medium to be read.\r
+  @param Offset                 The starting byte offset on the logical block I/O device to read from.\r
+  @param Token                  A pointer to the token associated with the transaction.\r
+                                If this field is NULL, synchronous/blocking IO is performed.\r
+  @param  BufferSize            The size in bytes of Buffer. The number of bytes to read from the device.\r
+  @param  Buffer                A pointer to the destination buffer for the data.\r
+                                The caller is responsible either having implicit or explicit ownership of the buffer.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was read correctly from the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId is not for the current medium.\r
+  @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not valid for the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2ReadDiskEx (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN UINT32                       MediaId,\r
+  IN UINT64                       Offset,\r
+  IN OUT EFI_DISK_IO2_TOKEN       *Token,\r
+  IN UINTN                        BufferSize,\r
+  OUT VOID                        *Buffer\r
+  );\r
+\r
+/**\r
+  Writes a specified number of bytes to a device.\r
+\r
+  @param This        Indicates a pointer to the calling context.\r
+  @param MediaId     ID of the medium to be written.\r
+  @param Offset      The starting byte offset on the logical block I/O device to write to.\r
+  @param Token       A pointer to the token associated with the transaction.\r
+                     If this field is NULL, synchronous/blocking IO is performed.\r
+  @param BufferSize  The size in bytes of Buffer. The number of bytes to write to the device.\r
+  @param Buffer      A pointer to the buffer containing the data to be written.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was written correctly to the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_WRITE_PROTECTED   The device cannot be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write operation.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId is not for the current medium.\r
+  @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not valid for the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2WriteDiskEx (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN UINT32                       MediaId,\r
+  IN UINT64                       Offset,\r
+  IN EFI_DISK_IO2_TOKEN           *Token,\r
+  IN UINTN                        BufferSize,\r
+  IN VOID                         *Buffer\r
+  );\r
+\r
+/**\r
+  Flushes all modified data to the physical device.\r
+\r
+  @param This        Indicates a pointer to the calling context.\r
+  @param Token       A pointer to the token associated with the transaction.\r
+                     If this field is NULL, synchronous/blocking IO is performed.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was flushed successfully to the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_WRITE_PROTECTED   The device cannot be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write operation.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2FlushDiskEx (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN OUT EFI_DISK_IO2_TOKEN       *Token\r
+  );\r
+\r
 //\r
 // EFI Component Name Functions\r
 //\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 DiskIoComponentNameGetDriverName (\r
@@ -111,6 +390,75 @@ DiskIoComponentNameGetDriverName (
   OUT CHAR16                       **DriverName\r
   );\r
 \r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 DiskIoComponentNameGetControllerName (\r
@@ -121,4 +469,5 @@ DiskIoComponentNameGetControllerName (
   OUT CHAR16                                          **ControllerName\r
   );\r
 \r
+\r
 #endif\r