]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add BlockIO support to the emulator, still needs testing. Also update Emulator start...
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 31 May 2011 20:23:36 +0000 (20:23 +0000)
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 31 May 2011 20:23:36 +0000 (20:23 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11718 6f19259b-4bc3-4df7-8a09-765794883524

17 files changed:
InOsEmuPkg/EmuBlockIoDxe/ComponentName.c [new file with mode: 0644]
InOsEmuPkg/EmuBlockIoDxe/DriverConfiguration.c [new file with mode: 0644]
InOsEmuPkg/EmuBlockIoDxe/DriverDiagnostics.c [new file with mode: 0644]
InOsEmuPkg/EmuBlockIoDxe/EmuBlockIo.c [new file with mode: 0644]
InOsEmuPkg/EmuBlockIoDxe/EmuBlockIo.h [new file with mode: 0644]
InOsEmuPkg/EmuBlockIoDxe/EmuBlockIoDxe.inf [new file with mode: 0644]
InOsEmuPkg/InOsEmuPkg.dec
InOsEmuPkg/Include/Guid/EmuPhysicalDisk.h [new file with mode: 0644]
InOsEmuPkg/Include/Guid/EmuVirtualDisk.h [new file with mode: 0644]
InOsEmuPkg/Include/Protocol/EmuBlockIo.h [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/BlockIo.c [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/SecMain.c
InOsEmuPkg/Unix/Sec/SecMain.h
InOsEmuPkg/Unix/Sec/X64/SwitchStack.S
InOsEmuPkg/Unix/UnixX64.dsc
InOsEmuPkg/Unix/UnixX64.fdf
InOsEmuPkg/Unix/build64.sh

diff --git a/InOsEmuPkg/EmuBlockIoDxe/ComponentName.c b/InOsEmuPkg/EmuBlockIoDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..2cad6ca
--- /dev/null
@@ -0,0 +1,354 @@
+/**@file\r
+\r
+Copyright (c) 2006, 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
+\r
+Module Name:\r
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+**/\r
+\r
+#include "EmuBlockIo.h"\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
+EmuBlockIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  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 not a valid EFI_HANDLE.\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
+EmuBlockIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED  EFI_COMPONENT_NAME_PROTOCOL     gEmuBlockIoComponentName = {\r
+  EmuBlockIoComponentNameGetDriverName,\r
+  EmuBlockIoComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Component Name 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBlockIoComponentName2 = {\r
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuBlockIoComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuBlockIoComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+\r
+EFI_UNICODE_STRING_TABLE mEmuBlockIoDriverNameTable[] = {\r
+  { "eng;en", L"Emu Block I/O Driver" },\r
+  { NULL , NULL }\r
+};\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
+EmuBlockIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+          Language,\r
+          This->SupportedLanguages,\r
+          mEmuBlockIoDriverNameTable,\r
+          DriverName,\r
+           (BOOLEAN)(This == &gEmuBlockIoComponentName)\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 not a valid EFI_HANDLE.\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
+EmuBlockIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Make sure this driver is currently managing ControllerHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+             &gEmuIoThunkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  (VOID  **)&BlockIo,\r
+                  gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
+\r
+  return LookupUnicodeString2 (\r
+          Language,\r
+           This->SupportedLanguages,\r
+           Private->ControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gEmuBlockIoComponentName)\r
+          );\r
+}\r
diff --git a/InOsEmuPkg/EmuBlockIoDxe/DriverConfiguration.c b/InOsEmuPkg/EmuBlockIoDxe/DriverConfiguration.c
new file mode 100644 (file)
index 0000000..44a3cc3
--- /dev/null
@@ -0,0 +1,338 @@
+/**@file\r
+\r
+Copyright (c) 2006, 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
+\r
+Module Name:\r
+\r
+  DriverConfiguration.c\r
+\r
+Abstract:\r
+\r
+**/\r
+\r
+#include "EmuBlockIo.h"\r
+\r
+//\r
+// EFI Driver Configuration Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationSetOptions (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  CHAR8                                                  *Language,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationOptionsValid (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle  OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationForceDefaults (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  UINT32                                                 DefaultType,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  );\r
+\r
+//\r
+// EFI Driver Configuration Protocol\r
+//\r
+EFI_DRIVER_CONFIGURATION_PROTOCOL gEmuBlockIoDriverConfiguration = {\r
+  EmuBlockIoDriverConfigurationSetOptions,\r
+  EmuBlockIoDriverConfigurationOptionsValid,\r
+  EmuBlockIoDriverConfigurationForceDefaults,\r
+  "eng"\r
+};\r
+\r
+/*++\r
+\r
+  Routine Description:\r
+    Allows the user to set controller specific options for a controller that a \r
+    driver is currently managing.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to set options on.\r
+    ChildHandle      - The handle of the child controller to set options on.  This\r
+                       is an optional parameter that may be NULL.  It will be NULL \r
+                       for device drivers, and for a bus drivers that wish to set \r
+                       options for the bus controller.  It will not be NULL for a \r
+                       bus driver that wishes to set options for one of its child \r
+                       controllers.\r
+    Language         - A pointer to a three character ISO 639-2 language identifier.\r
+                       This is the language of the user interface that should be \r
+                       presented to the user, and it must match one of the languages \r
+                       specified in SupportedLanguages.  The number of languages \r
+                       supported by a driver is up to the driver writer.\r
+    ActionRequired   - A pointer to the action that the calling agent is required \r
+                       to perform when this function returns.  See "Related \r
+                       Definitions" for a list of the actions that the calling \r
+                       agent is required to perform prior to accessing \r
+                       ControllerHandle again.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The driver specified by This successfully set the \r
+                            configuration options for the controller specified \r
+                            by ControllerHandle..\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ActionRequired is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support setting \r
+                            configuration options for the controller specified by \r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+    EFI_DEVICE_ERROR      - A device error occurred while attempt to set the \r
+                            configuration options for the controller specified \r
+                            by ControllerHandle and ChildHandle.\r
+    EFI_OUT_RESOURCES     - There are not enough resources available to set the \r
+                            configuration options for the controller specified \r
+                            by ControllerHandle and ChildHandle.\r
+\r
+--*/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationSetOptions (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  CHAR8                                                  *Language,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  CHAR8                 *SupportedLanguage;\r
+\r
+  SupportedLanguage = This->SupportedLanguages;\r
+\r
+  Status            = EFI_UNSUPPORTED;\r
+  while (*SupportedLanguage != 0) {\r
+    if (AsciiStrnCmp (Language, SupportedLanguage, 3) == 0) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
+\r
+    SupportedLanguage += 3;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (ActionRequired == NULL || ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&BlockIo,\r
+                  gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *ActionRequired = EfiDriverConfigurationActionNone;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/*++\r
+\r
+  Routine Description:\r
+    Tests to see if a controller's current configuration options are valid.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to test if it's current \r
+                       configuration options are valid.\r
+    ChildHandle      - The handle of the child controller to test if it's current\r
+                       configuration options are valid.  This is an optional \r
+                       parameter that may be NULL.  It will be NULL for device \r
+                       drivers.  It will also be NULL for a bus drivers that wish\r
+                       to test the configuration options for the bus controller.\r
+                       It will not be NULL for a bus driver that wishes to test \r
+                       configuration options for one of its child controllers.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The controller specified by ControllerHandle and \r
+                            ChildHandle that is being managed by the driver \r
+                            specified by This has a valid set of  configuration\r
+                            options.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently \r
+                            managing the controller specified by ControllerHandle \r
+                            and ChildHandle.\r
+    EFI_DEVICE_ERROR      - The controller specified by ControllerHandle and \r
+                            ChildHandle that is being managed by the driver \r
+                            specified by This has an invalid set of configuration \r
+                            options.\r
+\r
+--*/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationOptionsValid (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle  OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&BlockIo,\r
+                  gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/*++\r
+\r
+  Routine Description:\r
+    Forces a driver to set the default configuration options for a controller.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to force default configuration options on.\r
+    ChildHandle      - The handle of the child controller to force default configuration options on  This is an optional parameter that may be NULL.  It will be NULL for device drivers.  It will also be NULL for a bus drivers that wish to force default configuration options for the bus controller.  It will not be NULL for a bus driver that wishes to force default configuration options for one of its child controllers.\r
+    DefaultType      - The type of default configuration options to force on the controller specified by ControllerHandle and ChildHandle.  See Table 9-1 for legal values.  A DefaultType of 0x00000000 must be supported by this protocol.\r
+    ActionRequired   - A pointer to the action that the calling agent is required to perform when this function returns.  See "Related Definitions" in Section 9.1for a list of the actions that the calling agent is required to perform prior to accessing ControllerHandle again.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The driver specified by This successfully forced the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ActionRequired is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support forcing the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the configuration type specified by DefaultType.\r
+    EFI_DEVICE_ERROR      - A device error occurred while attempt to force the default configuration options on the controller specified by  ControllerHandle and ChildHandle.\r
+    EFI_OUT_RESOURCES     - There are not enough resources available to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+\r
+--*/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverConfigurationForceDefaults (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  UINT32                                                 DefaultType,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (ActionRequired == NULL || ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&BlockIo,\r
+                  gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *ActionRequired = EfiDriverConfigurationActionNone;\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/InOsEmuPkg/EmuBlockIoDxe/DriverDiagnostics.c b/InOsEmuPkg/EmuBlockIoDxe/DriverDiagnostics.c
new file mode 100644 (file)
index 0000000..ebb730b
--- /dev/null
@@ -0,0 +1,219 @@
+/**@file\r
+\r
+Copyright (c) 2006 - 2007, 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
+\r
+Module Name:\r
+\r
+  DriverDiagnostics.c\r
+\r
+Abstract:\r
+\r
+**/\r
+\r
+#include "EmuBlockIo.h"\r
+\r
+//\r
+// EFI Driver Diagnostics Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverDiagnosticsRunDiagnostics (\r
+  IN  EFI_DRIVER_DIAGNOSTICS_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                    ControllerHandle,\r
+  IN  EFI_HANDLE                                    ChildHandle  OPTIONAL,\r
+  IN  EFI_DRIVER_DIAGNOSTIC_TYPE                    DiagnosticType,\r
+  IN  CHAR8                                         *Language,\r
+  OUT EFI_GUID                                      **ErrorType,\r
+  OUT UINTN                                         *BufferSize,\r
+  OUT CHAR16                                        **Buffer\r
+  );\r
+\r
+//\r
+// EFI Driver Diagnostics Protocol\r
+//\r
+EFI_DRIVER_DIAGNOSTICS_PROTOCOL gEmuBlockIoDriverDiagnostics = {\r
+  EmuBlockIoDriverDiagnosticsRunDiagnostics,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Driver Diagnostics 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gEmuBlockIoDriverDiagnostics2 = {\r
+  (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS) EmuBlockIoDriverDiagnosticsRunDiagnostics,\r
+  "en"\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverDiagnosticsRunDiagnostics (\r
+  IN  EFI_DRIVER_DIAGNOSTICS_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                    ControllerHandle,\r
+  IN  EFI_HANDLE                                    ChildHandle  OPTIONAL,\r
+  IN  EFI_DRIVER_DIAGNOSTIC_TYPE                    DiagnosticType,\r
+  IN  CHAR8                                         *Language,\r
+  OUT EFI_GUID                                      **ErrorType,\r
+  OUT UINTN                                         *BufferSize,\r
+  OUT CHAR16                                        **Buffer\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Runs diagnostics on a controller.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to run diagnostics on.\r
+    ChildHandle      - The handle of the child controller to run diagnostics on  \r
+                       This is an optional parameter that may be NULL.  It will \r
+                       be NULL for device drivers.  It will also be NULL for a \r
+                       bus drivers that wish to run diagnostics on the bus \r
+                       controller.  It will not be NULL for a bus driver that \r
+                       wishes to run diagnostics on one of its child controllers.\r
+    DiagnosticType   - Indicates type of diagnostics to perform on the controller \r
+                       specified by ControllerHandle and ChildHandle.   See \r
+                       "Related Definitions" for the list of supported types.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier or a Null-terminated ASCII string array indicating\r
+                       the language.  This is the language in which the optional\r
+                       error message should be returned in Buffer, and it must \r
+                       match one of the languages specified in SupportedLanguages.\r
+                       The number of languages supported by a driver is up to \r
+                       the driver writer.  \r
+    ErrorType        - A GUID that defines the format of the data returned in \r
+                       Buffer.  \r
+    BufferSize       - The size, in bytes, of the data returned in Buffer.  \r
+    Buffer           - A buffer that contains a Null-terminated Unicode string \r
+                       plus some additional data whose format is defined by \r
+                       ErrorType.  Buffer is allocated by this function with \r
+                       AllocatePool(), and it is the caller's responsibility \r
+                       to free it with a call to FreePool().  \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The controller specified by ControllerHandle and \r
+                            ChildHandle passed the diagnostic.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ErrorType is NULL.\r
+    EFI_INVALID_PARAMETER - BufferType is NULL.\r
+    EFI_INVALID_PARAMETER - Buffer is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support \r
+                            running diagnostics for the controller specified \r
+                            by ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            type of diagnostic specified by DiagnosticType.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+    EFI_OUT_OF_RESOURCES  - There are not enough resources available to complete\r
+                            the diagnostics.\r
+    EFI_OUT_OF_RESOURCES  - There are not enough resources available to return\r
+                            the status information in ErrorType, BufferSize, \r
+                            and Buffer.\r
+    EFI_DEVICE_ERROR      - The controller specified by ControllerHandle and \r
+                            ChildHandle did not pass the diagnostic.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  CHAR8                 *SupportedLanguages;\r
+  BOOLEAN               Iso639Language;\r
+  BOOLEAN               Found;\r
+  UINTN                 Index;\r
+\r
+  if (Language         == NULL ||\r
+      ErrorType        == NULL ||\r
+      Buffer           == NULL ||\r
+      ControllerHandle == NULL ||\r
+      BufferSize       == NULL) {\r
+\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  SupportedLanguages = This->SupportedLanguages;\r
+  Iso639Language = (BOOLEAN)(This == &gEmuBlockIoDriverDiagnostics);\r
+  //\r
+  // Make sure Language is in the set of Supported Languages\r
+  //\r
+  Found = FALSE;\r
+  while (*SupportedLanguages != 0) {\r
+    if (Iso639Language) {\r
+      if (CompareMem (Language, SupportedLanguages, 3) == 0) {\r
+        Found = TRUE;\r
+      break;\r
+    }\r
+      SupportedLanguages += 3;\r
+    } else {\r
+      for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
+      if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r
+        Found = TRUE;\r
+        break;\r
+  }\r
+      SupportedLanguages += Index;\r
+      for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
+    }\r
+  }\r
+  //\r
+  // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
+  //\r
+  if (!Found) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  *ErrorType  = NULL;\r
+  *BufferSize = 0;\r
+  if (DiagnosticType != EfiDriverDiagnosticTypeStandard) {\r
+    *ErrorType  = &gEfiBlockIoProtocolGuid;\r
+    *BufferSize = 0x60;\r
+    Buffer = AllocatePool ((UINTN) (*BufferSize));\r
+    CopyMem (*Buffer, L"Windows Block I/O Driver Diagnostics Failed\n", *BufferSize);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&BlockIo,\r
+                  gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          gEmuBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/InOsEmuPkg/EmuBlockIoDxe/EmuBlockIo.c b/InOsEmuPkg/EmuBlockIoDxe/EmuBlockIo.c
new file mode 100644 (file)
index 0000000..999445b
--- /dev/null
@@ -0,0 +1,749 @@
+/**@file\r
+\r
+Copyright (c) 2004 - 2009, 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
+bbe\r
+**/\r
+\r
+#include "EmuBlockIo.h"\r
+\r
+\r
+/**\r
+  Reset the block device hardware.\r
+\r
+  @param[in]  This                 Indicates a pointer to the calling context.\r
+  @param[in]  ExtendedVerification Indicates that the driver may perform a more\r
+                                   exhausive verfication operation of the device\r
+                                   during 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
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIo2Reset (\r
+  IN EFI_BLOCK_IO2_PROTOCOL  *This,\r
+  IN BOOLEAN                 ExtendedVerification\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = Private->Io->Reset (Private->Io, ExtendedVerification);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Read BufferSize bytes from Lba into Buffer.\r
+  \r
+  This function reads the requested number of blocks from the device. All the\r
+  blocks are read, or an error is returned.\r
+  If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_or EFI_MEDIA_CHANGED is returned and\r
+  non-blocking I/O is being used, the Event associated with this request will\r
+  not be signaled.\r
+\r
+  @param[in]       This       Indicates a pointer to the calling context.\r
+  @param[in]       MediaId    Id of the media, changes every time the media is \r
+                              replaced.\r
+  @param[in]       Lba        The starting Logical Block Address to read from.\r
+  @param[in, out]  Token           A pointer to the token associated with the transaction.\r
+  @param[in]       BufferSize Size of Buffer, must be a multiple of device block size.  \r
+  @param[out]      Buffer     A pointer to the destination buffer for the data. The \r
+                              caller is responsible for either having implicit or \r
+                              explicit ownership of the buffer.\r
+\r
+  @retval EFI_SUCCESS           The read request was queued if Token->Event is\r
+                                not NULL.The data was read correctly from the\r
+                                device if the Token->Event is NULL.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing\r
+                                the read.\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
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack\r
+                                of resources.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIo2ReadBlocksEx (\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
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = Private->Io->ReadBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Write BufferSize bytes from Lba into Buffer.\r
+\r
+  This function writes the requested number of blocks to the device. All blocks\r
+  are written, or an error is returned.If EFI_DEVICE_ERROR, EFI_NO_MEDIA,\r
+  EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED is returned and non-blocking I/O is\r
+  being used, the Event associated with this request will not be signaled.\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 written. The\r
+                              caller is responsible for writing to only legitimate\r
+                              locations.\r
+  @param[in, out]  Token      A pointer to the token associated with the transaction.\r
+  @param[in]       BufferSize Size of Buffer, must be a multiple of device block size.\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 NULL.\r
+                                The data was written correctly to the device if\r
+                                the Event is NULL.\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_CHNAGED     The MediaId does not matched the current device.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\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
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack\r
+                                of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI \r
+EmuBlockIo2WriteBlocksEx (\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
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = Private->Io->WriteBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Flush the Block Device.\r
\r
+  If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED\r
+  is returned and non-blocking I/O is being used, the Event associated with\r
+  this request will not be signaled.  \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 transaction\r
+\r
+  @retval EFI_SUCCESS          The flush request was queued if Event is not NULL.\r
+                               All outstanding data was written correctly to the\r
+                               device if the Event is NULL.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error while writting back\r
+                               the 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 lack\r
+                               of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIo2Flush (\r
+  IN     EFI_BLOCK_IO2_PROTOCOL   *This,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN      *Token\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = Private->Io->FlushBlocks (Private->Io, Token);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\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
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoReset (\r
+  IN EFI_BLOCK_IO_PROTOCOL          *This,\r
+  IN BOOLEAN                        ExtendedVerification\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Status = Private->Io->Reset (Private->Io, ExtendedVerification);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\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
+EmuBlockIoReadBlocks\r
+(\r
+  IN EFI_BLOCK_IO_PROTOCOL          *This,\r
+  IN UINT32                         MediaId,\r
+  IN EFI_LBA                        Lba,\r
+  IN UINTN                          BufferSize,\r
+  OUT VOID                          *Buffer\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+  EFI_BLOCK_IO2_TOKEN     Token;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Token.Event = NULL;\r
+  Status = Private->Io->ReadBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\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
+EmuBlockIoWriteBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL          *This,\r
+  IN UINT32                         MediaId,\r
+  IN EFI_LBA                        Lba,\r
+  IN UINTN                          BufferSize,\r
+  IN VOID                           *Buffer\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+  EFI_BLOCK_IO2_TOKEN     Token;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Token.Event = NULL;\r
+  Status = Private->Io->WriteBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\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
+EmuBlockIoFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE    *Private;\r
+  EFI_TPL                 OldTpl;\r
+  EFI_BLOCK_IO2_TOKEN     Token;\r
+\r
+  Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Token.Event = NULL;\r
+  Status = Private->Io->FlushBlocks (Private->Io, &Token);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Tests to see if this driver supports a given controller. If a child device is provided, \r
+  it further tests to see if this driver supports creating a handle for the specified child device.\r
+\r
+  This function checks to see if the driver specified by This supports the device specified by \r
+  ControllerHandle. Drivers will typically use the device path attached to \r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to \r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function \r
+  may be called many times during platform initialization. In order to reduce boot times, the tests \r
+  performed by this function must be very small, and take as little time as possible to execute. This \r
+  function must not change the state of any hardware devices, and this function must be aware that the \r
+  device specified by ControllerHandle may already be managed by the same driver or a \r
+  different driver. This function must match its calls to AllocatePages() with FreePages(), \r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().  \r
+  Because ControllerHandle may have been previously started by the same driver, if a protocol is \r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle \r
+                                   must support a protocol interface that supplies \r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
+                                   parameter is ignored by device drivers, and is optional for bus \r
+                                   drivers. For bus drivers, if this parameter is not NULL, then \r
+                                   the bus driver must determine if the bus controller specified \r
+                                   by ControllerHandle and the child controller specified \r
+                                   by RemainingDevicePath are both supported by this \r
+                                   bus driver.\r
+\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_IO_THUNK_PROTOCOL  *EmuIoThunk;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&EmuIoThunk,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Make sure GUID is for a File System handle.\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  if (CompareGuid (EmuIoThunk->Protocol, &gEmuVirtualDisksGuid)) {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEmuIoThunkProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Starts a device controller or a bus controller.\r
+\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this \r
+  common boot service. It is legal to call Start() from other locations, \r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.  \r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle \r
+                                   must support a protocol interface that supplies \r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
+                                   parameter is ignored by device drivers, and is optional for bus \r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles \r
+                                   for all the children of Controller are created by this driver.  \r
+                                   If this parameter is not NULL and the first Device Path Node is \r
+                                   not the End of Device Path Node, then only the handle for the \r
+                                   child device specified by the first Device Path Node of \r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is \r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EMU_IO_THUNK_PROTOCOL       *EmuIoThunk;\r
+  EMU_BLOCK_IO_PRIVATE        *Private;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  \r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (void *)&EmuIoThunk,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Set DiskType\r
+  //\r
+  if (!CompareGuid (EmuIoThunk->Protocol, &gEmuVirtualDisksGuid)) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Done;\r
+  }\r
+\r
+  Status = EmuIoThunk->Open (EmuIoThunk);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Private = AllocatePool (sizeof (EMU_BLOCK_IO_PRIVATE));\r
+  if (Private == NULL) {\r
+    goto Done;\r
+  }\r
+\r
+  Private->Signature = EMU_BLOCK_IO_PRIVATE_SIGNATURE;\r
+  Private->IoThunk   = EmuIoThunk;\r
+  Private->Io        = EmuIoThunk->Interface;\r
+  \r
+  Private->BlockIo.Revision    = EFI_BLOCK_IO_PROTOCOL_REVISION2;\r
+  Private->BlockIo.Media       = &Private->Media;\r
+  Private->BlockIo.Reset       = EmuBlockIoReset;\r
+  Private->BlockIo.ReadBlocks  = EmuBlockIoReadBlocks;\r
+  Private->BlockIo.WriteBlocks = EmuBlockIoWriteBlocks;\r
+  Private->BlockIo.FlushBlocks = EmuBlockIoFlushBlocks;\r
+\r
+  Private->BlockIo2.Media         = &Private->Media;\r
+  Private->BlockIo2.Reset         = EmuBlockIo2Reset;\r
+  Private->BlockIo2.ReadBlocksEx  = EmuBlockIo2ReadBlocksEx;\r
+  Private->BlockIo2.WriteBlocksEx = EmuBlockIo2WriteBlocksEx;\r
+  Private->BlockIo2.FlushBlocksEx = (EFI_BLOCK_FLUSH_EX)EmuBlockIoFlushBlocks;\r
+\r
+  Private->ControllerNameTable = NULL;\r
+\r
+  Status = Private->Io->CreateMapping (Private->Io, &Private->Media);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  AddUnicodeString2 (\r
+    "eng",\r
+    gEmuBlockIoComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    EmuIoThunk->ConfigString,\r
+    TRUE\r
+    );\r
+    \r
+  AddUnicodeString2 (\r
+    "en",\r
+    gEmuBlockIoComponentName2.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    EmuIoThunk->ConfigString,\r
+    FALSE\r
+    );\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiBlockIoProtocolGuid,    &Private->BlockIo,\r
+                  &gEfiBlockIo2ProtocolGuid,   &Private->BlockIo2,\r
+                  NULL\r
+                  );\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    if (Private != NULL) {\r
+      if (Private->ControllerNameTable != NULL) {\r
+        FreeUnicodeStringTable (Private->ControllerNameTable);\r
+      }\r
+      \r
+      gBS->FreePool (Private);\r
+    \r
+    }\r
+    \r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Stops a device controller or a bus controller.\r
+  \r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
+  As a result, much of the error checking on the parameters to Stop() has been moved \r
+  into this common boot service. It is legal to call Stop() from other locations, \r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+  \r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must \r
+                                support a bus specific I/O protocol for the driver \r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL \r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EmuBlockIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE *Private;\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  (void *)&BlockIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
+  Status = Private->IoThunk->Close (Private->IoThunk);\r
+\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Private->EfiHandle,\r
+                  &gEfiBlockIoProtocolGuid,   &Private->BlockIo,\r
+                  &gEfiBlockIo2ProtocolGuid,  &Private->BlockIo2,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->CloseProtocol (\r
+                    Handle,\r
+                    &gEmuIoThunkProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    Handle\r
+                    );\r
+  }\r
+  \r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Free our instance data\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+    gBS->FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gEmuBlockIoDriverBinding = {\r
+  EmuBlockIoDriverBindingSupported,\r
+  EmuBlockIoDriverBindingStart,\r
+  EmuBlockIoDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+\r
+\r
+\r
+/**\r
+  The user Entry Point for module EmuBlockIo . 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
+InitializeEmuBlockIo (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallAllDriverProtocols2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gEmuBlockIoDriverBinding,\r
+             ImageHandle,\r
+             &gEmuBlockIoComponentName,\r
+             &gEmuBlockIoComponentName2,\r
+             NULL,\r
+             NULL,\r
+             &gEmuBlockIoDriverDiagnostics,\r
+             &gEmuBlockIoDriverDiagnostics2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+\r
diff --git a/InOsEmuPkg/EmuBlockIoDxe/EmuBlockIo.h b/InOsEmuPkg/EmuBlockIoDxe/EmuBlockIo.h
new file mode 100644 (file)
index 0000000..b11f305
--- /dev/null
@@ -0,0 +1,84 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2008, 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
+\r
+Module Name:\r
+\r
+  EmuBlockIo.h\r
+\r
+Abstract:\r
+\r
+  Produce block IO abstractions for real devices on your PC using Posix APIs.\r
+  The configuration of what devices to mount or emulate comes from UNIX \r
+  environment variables. The variables must be visible to the Microsoft* \r
+  Developer Studio for them to work.\r
+\r
+  * Other names and brands may be claimed as the property of others.\r
+\r
+**/\r
+\r
+#ifndef _EMU_BLOCK_IO_H_\r
+#define _EMU_BLOCK_IO_H_\r
+\r
+#include <PiDxe.h>\r
+#include <Protocol/EmuIoThunk.h>\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/BlockIo2.h>\r
+#include <Protocol/EmuBlockIo.h>\r
+\r
+#include <Guid/EmuPhysicalDisk.h>\r
+#include <Guid/EmuVirtualDisk.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+\r
+//\r
+// Language supported for driverconfiguration protocol\r
+//\r
+\r
+#define EMU_BLOCK_IO_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'M', 'b', 'k')\r
+typedef struct {\r
+  UINTN                       Signature;\r
+  EMU_IO_THUNK_PROTOCOL       *IoThunk;\r
+  EMU_BLOCK_IO_PROTOCOL       *Io;\r
+\r
+  EFI_HANDLE                  EfiHandle;\r
+  EFI_BLOCK_IO_PROTOCOL       BlockIo;\r
+  EFI_BLOCK_IO2_PROTOCOL      BlockIo2;\r
+  EFI_BLOCK_IO_MEDIA          Media;\r
+\r
+  EFI_UNICODE_STRING_TABLE    *ControllerNameTable;\r
+\r
+} EMU_BLOCK_IO_PRIVATE;\r
+\r
+#define EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, EMU_BLOCK_IO_PRIVATE, BlockIo, EMU_BLOCK_IO_PRIVATE_SIGNATURE)\r
+\r
+#define EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, EMU_BLOCK_IO_PRIVATE, BlockIo2, EMU_BLOCK_IO_PRIVATE_SIGNATURE)\r
+\r
+\r
+//\r
+// Block I/O Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL        gEmuBlockIoDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL        gEmuBlockIoComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL       gEmuBlockIoComponentName2;\r
+extern EFI_DRIVER_CONFIGURATION_PROTOCOL  gEmuBlockIoDriverConfiguration;\r
+extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL    gEmuBlockIoDriverDiagnostics;\r
+extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL   gEmuBlockIoDriverDiagnostics2;\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/EmuBlockIoDxe/EmuBlockIoDxe.inf b/InOsEmuPkg/EmuBlockIoDxe/EmuBlockIoDxe.inf
new file mode 100644 (file)
index 0000000..24f4759
--- /dev/null
@@ -0,0 +1,69 @@
+## @file\r
+# Block Io driver\r
+#\r
+# Produce block IO abstractions for real devices on your PC using Unix APIs.\r
+#  The configuration of what devices to mount or emulate comes from\r
+#  environment variables.\r
+# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#\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
+#  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
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = EmuBlockIo\r
+  FILE_GUID                      = C6760651-A38D-5F4F-AEAF-F6661549DF75\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeEmuBlockIo\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gUnixBlockIoDriverBinding                    \r
+#  COMPONENT_NAME                =  gUnixBlockIoComponentName                    \r
+#  DRIVER_DIAG                   =  gUnixBlockIoDriverDiagnostics                \r
+#\r
+\r
+[Sources]\r
+  DriverDiagnostics.c\r
+  DriverConfiguration.c\r
+  ComponentName.c\r
+  EmuBlockIo.c\r
+  EmuBlockIo.h\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEmuPhysicalDisksGuid                    # SOMETIMES_CONSUMED\r
+  gEmuVirtualDisksGuid                     # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiBlockIoProtocolGuid                     # PROTOCOL BY_START\r
+  gEfiBlockIo2ProtocolGuid                    # PROTOCOL BY_START\r
+  gEmuIoThunkProtocolGuid                     # PROTOCOL TO_START\r
+\r
index 9d49e6b642b4bb7d8b5a30dc465b83f78830b519..3a7417fd970c293e01edc585d85b4239edc2b4b5 100644 (file)
@@ -43,9 +43,9 @@
 [Guids]\r
   gInOsEmuPkgTokenSpaceGuid  = { 0x4F792E68, 0xE8C8, 0x794E, { 0xB1, 0xD8, 0x37, 0x03, 0xF3, 0xF2, 0xD5, 0xA5 } }\r
   gEmuSystemConfigGuid       = { 0xF8626165, 0x6CEB, 0x924A, { 0xBA, 0xFC, 0xF1, 0x3A, 0xB9, 0xD6, 0x57, 0x28 } }\r
+  gEmuVirtualDisksGuid       = { 0xf2ba331a, 0x8985, 0x11db, { 0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } }\r
+  gEmuPhysicalDisksGuid      = { 0xf2bdcc96, 0x8985, 0x11db, { 0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } }\r
 \r
-#  gEmuVirtualDisksGuid       = {0xf2ba331a, 0x8985, 0x11db, {0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
-#  gEmuPhysicalDisksGuid      = {0xf2bdcc96, 0x8985, 0x11db, {0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
 #  gEmuFileSystemGuid         = {0xf2c16b9e, 0x8985, 0x11db, {0x92, 0xc8, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
 #  gEmuSerialPortGuid         = {0x6d3a727d, 0x66c8, 0x4d19, {0x87, 0xe6, 0x02, 0x15, 0x86, 0x14, 0x90, 0xf3}}\r
 #  gEmuNetworkGuid            = {0x081603B4, 0x0F1D, 0x4022, {0xB6, 0xFD, 0x4C, 0xE3, 0x5E, 0x09, 0xA1, 0xA6}}\r
diff --git a/InOsEmuPkg/Include/Guid/EmuPhysicalDisk.h b/InOsEmuPkg/Include/Guid/EmuPhysicalDisk.h
new file mode 100644 (file)
index 0000000..324dc04
--- /dev/null
@@ -0,0 +1,24 @@
+/** @file\r
+  Setup Variable data structure for Emu platform.\r
+\r
+Copyright (c) 2009, 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
+\r
+\r
+**/\r
+\r
+#ifndef __EMU_PHYSICAL_DISK_H__\r
+#define __EMU_PHYSICAL_DISK_H__\r
+\r
+#define EFI_EMU_PHYSICAL_DISK_GUID  \\r
+ { 0xf2ba331a, 0x8985, 0x11db, { 0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } }\r
+\r
+extern EFI_GUID   gEmuPhysicalDisksGuid;\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/Include/Guid/EmuVirtualDisk.h b/InOsEmuPkg/Include/Guid/EmuVirtualDisk.h
new file mode 100644 (file)
index 0000000..17b97dc
--- /dev/null
@@ -0,0 +1,24 @@
+/** @file\r
+  Setup Variable data structure for Emu platform.\r
+\r
+Copyright (c) 2009, 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
+\r
+\r
+**/\r
+\r
+#ifndef __EMU_VIRTUAL_DISK_H__\r
+#define __EMU_VIRTUAL_DISK_H__\r
+\r
+#define EFI_EMU_VIRTUAL_DISK_GUID  \\r
+ { 0xf2ba331a, 0x8985, 0x11db, { 0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } }\r
+\r
+extern EFI_GUID   gEmuVirtualDisksGuid;\r
+\r
+#endif\r
diff --git a/InOsEmuPkg/Include/Protocol/EmuBlockIo.h b/InOsEmuPkg/Include/Protocol/EmuBlockIo.h
new file mode 100644 (file)
index 0000000..f31124d
--- /dev/null
@@ -0,0 +1,192 @@
+/** @file\r
+  Emu Block IO2 protocol as defined in the UEFI 2.3.1 specification.\r
+\r
+  The Block IO2 protocol defines an extension to the Block IO protocol which\r
+  enables the ability to read and write data at a block level in a non-blocking\r
+  manner.\r
+\r
+  Copyright (c) 2011, 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
+\r
+**/\r
+\r
+#ifndef __EMU_BLOCK_IO_H__\r
+#define __EMU_BLOCK_IO_H__\r
+\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/BlockIo2.h>\r
+\r
+#define EMU_BLOCK_IO_PROTOCOL_GUID \\r
+ { 0x3EC5F7E0, 0x1124, 0xDF45, { 0x9F, 0x96, 0x7D, 0xD6, 0x63, 0xC0, 0xAF, 0xE7 } }\r
+\r
+typedef struct _EMU_BLOCK_IO_PROTOCOL   EMU_BLOCK_IO_PROTOCOL;\r
+\r
+\r
+\r
+/**\r
+  Reset the block device hardware.\r
+\r
+  @param[in]  This                 Indicates a pointer to the calling context.\r
+  @param[in]  ExtendedVerification Indicates that the driver may perform a more\r
+                                   exhausive verfication operation of the device\r
+                                   during 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
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMU_BLOCK_RESET) (\r
+  IN EMU_BLOCK_IO_PROTOCOL   *This,\r
+  IN BOOLEAN                 ExtendedVerification\r
+  );\r
+\r
+/**\r
+  Read BufferSize bytes from Lba into Buffer.\r
+  \r
+  This function reads the requested number of blocks from the device. All the\r
+  blocks are read, or an error is returned.\r
+  If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_or EFI_MEDIA_CHANGED is returned and\r
+  non-blocking I/O is being used, the Event associated with this request will\r
+  not be signaled.\r
+\r
+  @param[in]       This       Indicates a pointer to the calling context.\r
+  @param[in]       MediaId    Id of the media, changes every time the media is \r
+                              replaced.\r
+  @param[in]       Lba        The starting Logical Block Address to read from.\r
+  @param[in, out]  Token           A pointer to the token associated with the transaction.\r
+  @param[in]       BufferSize Size of Buffer, must be a multiple of device block size.  \r
+  @param[out]      Buffer     A pointer to the destination buffer for the data. The \r
+                              caller is responsible for either having implicit or \r
+                              explicit ownership of the buffer.\r
+\r
+  @retval EFI_SUCCESS           The read request was queued if Token->Event is\r
+                                not NULL.The data was read correctly from the\r
+                                device if the Token->Event is NULL.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing\r
+                                the read.\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
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack\r
+                                of resources.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMU_BLOCK_READ) (\r
+  IN     EMU_BLOCK_IO_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
+  Write BufferSize bytes from Lba into Buffer.\r
+\r
+  This function writes the requested number of blocks to the device. All blocks\r
+  are written, or an error is returned.If EFI_DEVICE_ERROR, EFI_NO_MEDIA,\r
+  EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED is returned and non-blocking I/O is\r
+  being used, the Event associated with this request will not be signaled.\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 written. The\r
+                              caller is responsible for writing to only legitimate\r
+                              locations.\r
+  @param[in, out]  Token      A pointer to the token associated with the transaction.\r
+  @param[in]       BufferSize Size of Buffer, must be a multiple of device block size.\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 NULL.\r
+                                The data was written correctly to the device if\r
+                                the Event is NULL.\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_CHNAGED     The MediaId does not matched the current device.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\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
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack\r
+                                of resources.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMU_BLOCK_WRITE) (\r
+  IN     EMU_BLOCK_IO_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
+  Flush the Block Device.\r
\r
+  If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED\r
+  is returned and non-blocking I/O is being used, the Event associated with\r
+  this request will not be signaled.  \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 transaction\r
+\r
+  @retval EFI_SUCCESS          The flush request was queued if Event is not NULL.\r
+                               All outstanding data was written correctly to the\r
+                               device if the Event is NULL.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error while writting back\r
+                               the 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 lack\r
+                               of resources.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMU_BLOCK_FLUSH) (\r
+  IN     EMU_BLOCK_IO_PROTOCOL    *This,\r
+  IN OUT EFI_BLOCK_IO2_TOKEN      *Token\r
+  );\r
+\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EMU_BLOCK_CREATE_MAPPING) (\r
+  IN     EMU_BLOCK_IO_PROTOCOL    *This,\r
+  IN     EFI_BLOCK_IO_MEDIA       *Media\r
+  );\r
+\r
+\r
+///\r
+///  The Block I/O2 protocol defines an extension to the Block I/O protocol which\r
+///  enables the ability to read and write data at a block level in a non-blocking\r
+//   manner.\r
+///\r
+struct _EMU_BLOCK_IO_PROTOCOL  {\r
+  EMU_BLOCK_RESET           Reset;\r
+  EMU_BLOCK_READ            ReadBlocks;\r
+  EMU_BLOCK_WRITE           WriteBlocks;\r
+  EMU_BLOCK_FLUSH           FlushBlocks;\r
+  EMU_BLOCK_CREATE_MAPPING  CreateMapping;\r
+};\r
+\r
+extern EFI_GUID gEmuBlockIoProtocolGuid;\r
+\r
+#endif\r
+\r
diff --git a/InOsEmuPkg/Unix/Sec/BlockIo.c b/InOsEmuPkg/Unix/Sec/BlockIo.c
new file mode 100644 (file)
index 0000000..3fc1d3f
--- /dev/null
@@ -0,0 +1,1053 @@
+/**@file\r
+\r
+Copyright (c) 2004 - 2009, 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
+\r
+Module Name:\r
+\r
+  UnixBlockIo.c\r
+\r
+Abstract:\r
+\r
+  Produce block IO abstractions for real devices on your PC using Posix APIs.\r
+  The configuration of what devices to mount or emulate comes from UNIX \r
+  environment variables. The variables must be visible to the Microsoft* \r
+  Developer Studio for them to work.\r
+\r
+  <F>ixed       - Fixed disk like a hard drive.\r
+  <R>emovable   - Removable media like a floppy or CD-ROM.\r
+  Read <O>nly   - Write protected device.\r
+  Read <W>rite  - Read write device.\r
+  <block count> - Decimal number of blocks a device supports.\r
+  <block size>  - Decimal number of bytes per block.\r
+\r
+  UNIX envirnonment variable contents. '<' and '>' are not part of the variable, \r
+  they are just used to make this help more readable. There should be no \r
+  spaces between the ';'. Extra spaces will break the variable. A '!' is \r
+  used to seperate multiple devices in a variable.\r
+\r
+  EFI_EMU_VIRTUAL_DISKS = \r
+    <F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+  EFI_EMU_PHYSICAL_DISKS =\r
+    <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+  Virtual Disks: These devices use a file to emulate a hard disk or removable\r
+                 media device. \r
+                 \r
+    Thus a 20 MB emulated hard drive would look like:\r
+    EFI_EMU_VIRTUAL_DISKS=FW;40960;512\r
+\r
+    A 1.44MB emulated floppy with a block size of 1024 would look like:\r
+    EFI_EMU_VIRTUAL_DISKS=RW;1440;1024\r
+\r
+  Physical Disks: These devices use UNIX to open a real device in your system\r
+\r
+    Thus a 120 MB floppy would look like:\r
+    EFI_EMU_PHYSICAL_DISKS=B:RW;245760;512\r
+\r
+    Thus a standard CD-ROM floppy would look like:\r
+    EFI_EMU_PHYSICAL_DISKS=Z:RO;307200;2048\r
+\r
+\r
+  * Other names and brands may be claimed as the property of others.\r
+\r
+**/\r
+\r
+#include <fcntl.h>\r
+#include <unistd.h>\r
+#include "UnixBlockIo.h"\r
+\r
+//\r
+// Block IO protocol member functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoReadBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  OUT VOID                  *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoWriteBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  IN VOID                   *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoResetBlock (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN BOOLEAN                ExtendedVerification\r
+  );\r
+\r
+//\r
+// Private Worker functions\r
+//\r
+EFI_STATUS\r
+UnixBlockIoCreateMapping (\r
+  IN EMU_IO_THUNK_PROTOCOL             *EmuIoThunk,\r
+  IN EFI_HANDLE                         EfiDeviceHandle,\r
+  IN CHAR16                             *Filename,\r
+  IN BOOLEAN                            ReadOnly,\r
+  IN BOOLEAN                            RemovableMedia,\r
+  IN UINTN                              NumberOfBlocks,\r
+  IN UINTN                              BlockSize\r
+  );\r
+\r
+EFI_STATUS\r
+UnixBlockIoReadWriteCommon (\r
+  IN  EMU_BLOCK_IO_PRIVATE *Private,\r
+  IN UINT32                   MediaId,\r
+  IN EFI_LBA                  Lba,\r
+  IN UINTN                    BufferSize,\r
+  IN VOID                     *Buffer,\r
+  IN CHAR8                    *CallerName\r
+  );\r
+\r
+EFI_STATUS\r
+UnixBlockIoError (\r
+  IN EMU_BLOCK_IO_PRIVATE      *Private\r
+  );\r
+\r
+EFI_STATUS\r
+UnixBlockIoOpenDevice (\r
+  EMU_BLOCK_IO_PRIVATE         *Private\r
+  );\r
+\r
+CHAR16                                    *\r
+GetNextElementPastTerminator (\r
+  IN  CHAR16  *EnvironmentVariable,\r
+  IN  CHAR16  Terminator\r
+  );\r
+\r
+\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gUnixBlockIoDriverBinding = {\r
+  UnixBlockIoDriverBindingSupported,\r
+  UnixBlockIoDriverBindingStart,\r
+  UnixBlockIoDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+/**\r
+  The user Entry Point for module UnixBlockIo. 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
+InitializeUnixBlockIo(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallAllDriverProtocols2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gUnixBlockIoDriverBinding,\r
+             ImageHandle,\r
+             &gUnixBlockIoComponentName,\r
+             &gUnixBlockIoComponentName2,\r
+             NULL,\r
+             &gUnixBlockIoDriverDiagnostics,\r
+             &gUnixBlockIoDriverDiagnostics2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+**/\r
+{\r
+  EFI_STATUS              Status;\r
+  EMU_IO_THUNK_PROTOCOL  *EmuIoThunk;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (VOID **)&EmuIoThunk,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Make sure the UnixThunkProtocol is valid\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  if (EmuIoThunk->UnixThunk->Signature == EFI_EMU_THUNK_PROTOCOL_SIGNATURE) {\r
+\r
+    //\r
+    // Check the GUID to see if this is a handle type the driver supports\r
+    //\r
+    if (CompareGuid (EmuIoThunk->TypeGuid, &gEfiUnixVirtualDisksGuid) ) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEmuIoThunkProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+**/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EMU_IO_THUNK_PROTOCOL       *EmuIoThunk;\r
+  CHAR16                      Buffer[FILENAME_BUFFER_SIZE];\r
+  CHAR16                      *Str;\r
+  BOOLEAN                     RemovableMedia;\r
+  BOOLEAN                     WriteProtected;\r
+  UINTN                       NumberOfBlocks;\r
+  UINTN                       BlockSize;\r
+  INTN                        i;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  \r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEmuIoThunkProtocolGuid,\r
+                  (void *)&EmuIoThunk,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Set DiskType\r
+  //\r
+  if (!CompareGuid (EmuIoThunk->TypeGuid, &gEfiUnixVirtualDisksGuid)) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Done;\r
+  }\r
+\r
+  Status  = EFI_NOT_FOUND;\r
+  //  Extract filename.\r
+  Str     = EmuIoThunk->EnvString;\r
+  i = 0;\r
+  while (*Str && *Str != ':')\r
+    Buffer[i++] = *Str++;\r
+  Buffer[i] = 0;\r
+  if (*Str != ':') {\r
+    goto Done;\r
+  }\r
+\r
+  Str++;\r
+\r
+  RemovableMedia = FALSE;\r
+  WriteProtected = TRUE;\r
+  NumberOfBlocks = 0;\r
+  BlockSize = 512;\r
+  do {\r
+    if (*Str == 'R' || *Str == 'F') {\r
+      RemovableMedia = (BOOLEAN) (*Str == 'R');\r
+      Str++;\r
+    }\r
+    if (*Str == 'O' || *Str == 'W') {\r
+      WriteProtected  = (BOOLEAN) (*Str == 'O');\r
+      Str++;\r
+    }\r
+    if (*Str == 0)\r
+      break;\r
+    if (*Str != ';')\r
+      goto Done;\r
+    Str++;\r
+\r
+    NumberOfBlocks  = Atoi (Str);\r
+    Str       = GetNextElementPastTerminator (Str, ';');\r
+    if (NumberOfBlocks == 0)\r
+      break;\r
+\r
+    BlockSize = Atoi (Str);\r
+    if (BlockSize != 0)\r
+      Str       = GetNextElementPastTerminator (Str, ';');\r
+  } while (0);\r
+\r
+  //\r
+  // If we get here the variable is valid so do the work.\r
+  //\r
+  Status = UnixBlockIoCreateMapping (\r
+              EmuIoThunk,\r
+              Handle,\r
+              Buffer,\r
+              WriteProtected,\r
+              RemovableMedia,\r
+              NumberOfBlocks,\r
+              BlockSize\r
+              );\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEmuIoThunkProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  EFI_STATUS              Status;\r
+  EMU_BLOCK_IO_PRIVATE *Private;\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  (void *)&BlockIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
+\r
+  //\r
+  // BugBug: If we need to kick people off, we need to make Uninstall Close the handles.\r
+  //         We could pass in our image handle or FLAG our open to be closed via\r
+  //         Unistall (== to saying any CloseProtocol will close our open)\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Private->EfiHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  &Private->BlockIo,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+\r
+    Status = gBS->CloseProtocol (\r
+                    Handle,\r
+                    &gEmuIoThunkProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    Handle\r
+                    );\r
+\r
+    //\r
+    // Shut down our device\r
+    //\r
+    Private->UnixThunk->Close (Private->fd);\r
+\r
+    //\r
+    // Free our instance data\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+    gBS->FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+CHAR16 *\r
+GetNextElementPastTerminator (\r
+  IN  CHAR16  *EnvironmentVariable,\r
+  IN  CHAR16  Terminator\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Worker function to parse environment variables.\r
+\r
+Arguments:\r
+  EnvironmentVariable - Envirnment variable to parse.\r
+\r
+  Terminator          - Terminator to parse for.\r
+\r
+Returns: \r
+\r
+  Pointer to next eliment past the first occurence of Terminator or the '\0'\r
+  at the end of the string.\r
+\r
+**/\r
+{\r
+  CHAR16  *Ptr;\r
+\r
+  for (Ptr = EnvironmentVariable; *Ptr != '\0'; Ptr++) {\r
+    if (*Ptr == Terminator) {\r
+      Ptr++;\r
+      break;\r
+    }\r
+  }\r
+\r
+  return Ptr;\r
+}\r
+\r
+EFI_STATUS\r
+UnixBlockIoCreateMapping (\r
+  IN EMU_IO_THUNK_PROTOCOL             *EmuIoThunk,\r
+  IN EFI_HANDLE                         EfiDeviceHandle,\r
+  IN CHAR16                             *Filename,\r
+  IN BOOLEAN                            ReadOnly,\r
+  IN BOOLEAN                            RemovableMedia,\r
+  IN UINTN                              NumberOfBlocks,\r
+  IN UINTN                              BlockSize\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  EMU_BLOCK_IO_PRIVATE *Private;\r
+  UINTN                   Index;\r
+\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  sizeof (EMU_BLOCK_IO_PRIVATE),\r
+                  (void *)&Private\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  EfiInitializeLock (&Private->Lock, TPL_NOTIFY);\r
+\r
+  Private->UnixThunk = EmuIoThunk->UnixThunk;\r
+\r
+  Private->Signature  = EMU_BLOCK_IO_PRIVATE_SIGNATURE;\r
+  Private->LastBlock  = NumberOfBlocks - 1;\r
+  Private->BlockSize  = BlockSize;\r
+\r
+  for (Index = 0; Filename[Index] != 0; Index++) {\r
+    Private->Filename[Index] = Filename[Index];\r
+  }\r
+\r
+  Private->Filename[Index]      = 0;\r
+\r
+  Private->Mode                 = (ReadOnly ? O_RDONLY : O_RDWR);\r
+\r
+  Private->NumberOfBlocks       = NumberOfBlocks;\r
+  Private->fd                   = -1;\r
+\r
+  Private->ControllerNameTable  = NULL;\r
+\r
+  AddUnicodeString (\r
+    "eng",\r
+    gUnixBlockIoComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    Filename\r
+    );\r
+\r
+  BlockIo = &Private->BlockIo;\r
+  BlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION;\r
+  BlockIo->Media = &Private->Media;\r
+  BlockIo->Media->BlockSize = Private->BlockSize;\r
+  BlockIo->Media->LastBlock = Private->NumberOfBlocks - 1;\r
+  BlockIo->Media->MediaId = 0;;\r
+\r
+  BlockIo->Reset = UnixBlockIoResetBlock;\r
+  BlockIo->ReadBlocks = UnixBlockIoReadBlocks;\r
+  BlockIo->WriteBlocks = UnixBlockIoWriteBlocks;\r
+  BlockIo->FlushBlocks = UnixBlockIoFlushBlocks;\r
+\r
+  BlockIo->Media->ReadOnly = ReadOnly;\r
+  BlockIo->Media->RemovableMedia = RemovableMedia;\r
+  BlockIo->Media->LogicalPartition = FALSE;\r
+  BlockIo->Media->MediaPresent = TRUE;\r
+  BlockIo->Media->WriteCaching = FALSE;\r
+\r
+  BlockIo->Media->IoAlign = 1;\r
+\r
+  Private->EfiHandle  = EfiDeviceHandle;\r
+  Status              = UnixBlockIoOpenDevice (Private);\r
+  if (!EFI_ERROR (Status)) {\r
+\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &Private->EfiHandle,\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    &Private->BlockIo,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      FreeUnicodeStringTable (Private->ControllerNameTable);\r
+      gBS->FreePool (Private);\r
+    }\r
+\r
+    DEBUG ((EFI_D_ERROR, "BlockDevice added: %s\n", Filename));\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+UnixBlockIoOpenDevice (\r
+  EMU_BLOCK_IO_PRIVATE                 *Private\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINT64                FileSize;\r
+  UINT64                EndOfFile;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  BlockIo = &Private->BlockIo;\r
+  EfiAcquireLock (&Private->Lock);\r
+\r
+  //\r
+  // If the device is already opened, close it\r
+  //\r
+  if (Private->fd >= 0) {\r
+    BlockIo->Reset (BlockIo, FALSE);\r
+  }\r
+\r
+  //\r
+  // Open the device\r
+  //\r
+  Private->fd = Private->UnixThunk->Open (Private->Filename, Private->Mode, 0644);\r
+  if (Private->fd < 0) {\r
+    DEBUG ((EFI_D_INFO, "PlOpenBlock: Could not open %a\n", Private->Filename));\r
+    BlockIo->Media->MediaPresent  = FALSE;\r
+    Status                        = EFI_NO_MEDIA;\r
+    goto Done;\r
+  }\r
+\r
+  if (!BlockIo->Media->MediaPresent) {\r
+    //\r
+    // BugBug: try to emulate if a CD appears - notify drivers to check it out\r
+    //\r
+    BlockIo->Media->MediaPresent = TRUE;\r
+    EfiReleaseLock (&Private->Lock);\r
+    EfiAcquireLock (&Private->Lock);\r
+  }\r
+\r
+  //\r
+  // get the size of the file\r
+  //\r
+  Status = SetFilePointer64 (Private, 0, &FileSize, SEEK_END);\r
+  if (EFI_ERROR (Status)) {\r
+    FileSize = MultU64x32 (Private->NumberOfBlocks, Private->BlockSize);\r
+    DEBUG ((EFI_D_ERROR, "PlOpenBlock: Could not get filesize of %a\n", Private->Filename));\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Done;\r
+  }\r
+\r
+  if (Private->NumberOfBlocks == 0) {\r
+    Private->NumberOfBlocks = DivU64x32 (FileSize, Private->BlockSize);\r
+    Private->LastBlock = Private->NumberOfBlocks - 1;\r
+    Private->Media.LastBlock = Private->LastBlock;\r
+  }\r
+\r
+  EndOfFile = MultU64x32 (Private->NumberOfBlocks, Private->BlockSize);\r
+\r
+  if (FileSize != EndOfFile) {\r
+    //\r
+    // file is not the proper size, change it\r
+    //\r
+    DEBUG ((EFI_D_INIT, "PlOpenBlock: Initializing block device: %a\n", Private->Filename));\r
+\r
+    //\r
+    // first set it to 0\r
+    //\r
+    Private->UnixThunk->FTruncate (Private->fd, 0);\r
+\r
+    //\r
+    // then set it to the needed file size (OS will zero fill it)\r
+    //\r
+    Private->UnixThunk->FTruncate (Private->fd, EndOfFile);\r
+  }\r
+\r
+  DEBUG ((EFI_D_INIT, "%HPlOpenBlock: opened %a%N\n", Private->Filename));\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    if (Private->fd >= 0) {\r
+      BlockIo->Reset (BlockIo, FALSE);\r
+    }\r
+  }\r
+\r
+  EfiReleaseLock (&Private->Lock);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+UnixBlockIoError (\r
+  IN EMU_BLOCK_IO_PRIVATE      *Private\r
+  )\r
+{\r
+  return EFI_DEVICE_ERROR;\r
+\r
+#if 0\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  EFI_STATUS            Status;\r
+  BOOLEAN               ReinstallBlockIoFlag;\r
+\r
+\r
+  BlockIo = &Private->BlockIo;\r
+\r
+  switch (Private->UnixThunk->GetLastError ()) {\r
+\r
+  case ERROR_NOT_READY:\r
+    Status                        = EFI_NO_MEDIA;\r
+    BlockIo->Media->ReadOnly      = FALSE;\r
+    BlockIo->Media->MediaPresent  = FALSE;\r
+    ReinstallBlockIoFlag          = FALSE;\r
+    break;\r
+\r
+  case ERROR_WRONG_DISK:\r
+    BlockIo->Media->ReadOnly      = FALSE;\r
+    BlockIo->Media->MediaPresent  = TRUE;\r
+    BlockIo->Media->MediaId += 1;\r
+    ReinstallBlockIoFlag  = TRUE;\r
+    Status                = EFI_MEDIA_CHANGED;\r
+    break;\r
+\r
+  case ERROR_WRITE_PROTECT:\r
+    BlockIo->Media->ReadOnly  = TRUE;\r
+    ReinstallBlockIoFlag      = FALSE;\r
+    Status                    = EFI_WRITE_PROTECTED;\r
+    break;\r
+\r
+  default:\r
+    ReinstallBlockIoFlag  = FALSE;\r
+    Status                = EFI_DEVICE_ERROR;\r
+    break;\r
+  }\r
+\r
+  if (ReinstallBlockIoFlag) {\r
+    BlockIo->Reset (BlockIo, FALSE);\r
+\r
+    gBS->ReinstallProtocolInterface (\r
+          Private->EfiHandle,\r
+          &gEfiBlockIoProtocolGuid,\r
+          BlockIo,\r
+          BlockIo\r
+          );\r
+  }\r
+\r
+  return Status;\r
+#endif\r
+}\r
+\r
+EFI_STATUS\r
+UnixBlockIoReadWriteCommon (\r
+  IN  EMU_BLOCK_IO_PRIVATE     *Private,\r
+  IN UINT32                       MediaId,\r
+  IN EFI_LBA                      Lba,\r
+  IN UINTN                        BufferSize,\r
+  IN VOID                         *Buffer,\r
+  IN CHAR8                        *CallerName\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       BlockSize;\r
+  UINT64      LastBlock;\r
+  INT64       DistanceToMove;\r
+  UINT64      DistanceMoved;\r
+\r
+  if (Private->fd < 0) {\r
+    Status = UnixBlockIoOpenDevice (Private);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  if (!Private->Media.MediaPresent) {\r
+    DEBUG ((EFI_D_INIT, "%s: No Media\n", CallerName));\r
+    return EFI_NO_MEDIA;\r
+  }\r
+\r
+  if (Private->Media.MediaId != MediaId) {\r
+    return EFI_MEDIA_CHANGED;\r
+  }\r
+\r
+  if ((UINTN) Buffer % Private->Media.IoAlign != 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // Verify buffer size\r
+  //\r
+  BlockSize = Private->BlockSize;\r
+  if (BufferSize == 0) {\r
+    DEBUG ((EFI_D_INIT, "%s: Zero length read\n", CallerName));\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if ((BufferSize % BlockSize) != 0) {\r
+    DEBUG ((EFI_D_INIT, "%s: Invalid read size\n", CallerName));\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  LastBlock = Lba + (BufferSize / BlockSize) - 1;\r
+  if (LastBlock > Private->LastBlock) {\r
+    DEBUG ((EFI_D_INIT, "ReadBlocks: Attempted to read off end of device\n"));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Seek to End of File\r
+  //\r
+  DistanceToMove = MultU64x32 (Lba, BlockSize);\r
+  Status = SetFilePointer64 (Private, DistanceToMove, &DistanceMoved, SEEK_SET);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_INIT, "WriteBlocks: SetFilePointer failed\n"));\r
+    return UnixBlockIoError (Private);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoReadBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  OUT VOID                  *Buffer\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Read BufferSize bytes from Lba into Buffer.\r
+\r
+  Arguments:\r
+    This       - Protocol instance pointer.\r
+    MediaId    - Id of the media, changes every time the media is replaced.\r
+    Lba        - The starting Logical Block Address to read from\r
+    BufferSize - Size of Buffer, must be a multiple of device block size.\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_CHANGED     - The MediaId does not matched the current device.\r
+    EFI_BAD_BUFFER_SIZE   - The Buffer was not a multiple of the block size of the \r
+                            device.\r
+    EFI_INVALID_PARAMETER - The read request contains device addresses that are not \r
+                            valid for the device.\r
+\r
+**/\r
+{\r
+  EMU_BLOCK_IO_PRIVATE *Private;\r
+  ssize_t                 len;\r
+  EFI_STATUS              Status;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status  = UnixBlockIoReadWriteCommon (Private, MediaId, Lba, BufferSize, Buffer, "UnixReadBlocks");\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  len = Private->UnixThunk->Read (Private->fd, Buffer, BufferSize);\r
+  if (len != BufferSize) {\r
+    DEBUG ((EFI_D_INIT, "ReadBlocks: ReadFile failed.\n"));\r
+    Status = UnixBlockIoError (Private);\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // If we wrote then media is present.\r
+  //\r
+  This->Media->MediaPresent = TRUE;\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoWriteBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  IN VOID                   *Buffer\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Write BufferSize bytes from Lba into Buffer.\r
+\r
+  Arguments:\r
+    This       - Protocol instance pointer.\r
+    MediaId    - Id of the media, changes every time the media is replaced.\r
+    Lba        - The starting Logical Block Address to read from\r
+    BufferSize - Size of Buffer, must be a multiple of device block size.\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_BAD_BUFFER_SIZE   - The Buffer was not a multiple of the block size of the \r
+                            device.\r
+    EFI_INVALID_PARAMETER - The write request contains a LBA that is not \r
+                            valid for the device.\r
+\r
+**/\r
+{\r
+  EMU_BLOCK_IO_PRIVATE *Private;\r
+  ssize_t                 len;\r
+  EFI_STATUS              Status;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status  = UnixBlockIoReadWriteCommon (Private, MediaId, Lba, BufferSize, Buffer, "UnixWriteBlocks");\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  len = Private->UnixThunk->Write (Private->fd, Buffer, BufferSize);\r
+  if (len != BufferSize) {\r
+    DEBUG ((EFI_D_INIT, "ReadBlocks: WriteFile failed.\n"));\r
+    Status = UnixBlockIoError (Private);\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // If the write succeeded, we are not write protected and media is present.\r
+  //\r
+  This->Media->MediaPresent = TRUE;\r
+  This->Media->ReadOnly     = FALSE;\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Flush the Block Device.\r
+\r
+  Arguments:\r
+    This             - Protocol instance pointer.\r
+\r
+  Returns:\r
+    EFI_SUCCESS      - All outstanding data was written to the device\r
+    EFI_DEVICE_ERROR - The device reported an error while writting back the data\r
+    EFI_NO_MEDIA     - There is no media in the device.\r
+\r
+**/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoResetBlock (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN BOOLEAN                ExtendedVerification\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Reset the Block Device.\r
+\r
+  Arguments:\r
+    This                 - Protocol instance pointer.\r
+    ExtendedVerification - Driver may perform diagnostics on reset.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The device was reset.\r
+    EFI_DEVICE_ERROR      - The device is not functioning properly and could \r
+                            not be reset.\r
+\r
+**/\r
+{\r
+  EMU_BLOCK_IO_PRIVATE *Private;\r
+  EFI_TPL               OldTpl;\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (Private->fd >= 0) {\r
+    Private->UnixThunk->Close (Private->fd);\r
+    Private->fd = -1;\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+UINTN\r
+Atoi (\r
+  CHAR16  *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Convert a unicode string to a UINTN\r
+\r
+Arguments:\r
+\r
+  String - Unicode string.\r
+\r
+Returns: \r
+\r
+  UINTN of the number represented by String.  \r
+\r
+**/\r
+{\r
+  UINTN   Number;\r
+  CHAR16  *Str;\r
+\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  Str = String;\r
+  while ((*Str) && (*Str == ' ')) {\r
+    Str++;\r
+  }\r
+  //\r
+  // Convert ot a Number\r
+  //\r
+  Number = 0;\r
+  while (*Str != '\0') {\r
+    if ((*Str >= '0') && (*Str <= '9')) {\r
+      Number = (Number * 10) +*Str - '0';\r
+    } else {\r
+      break;\r
+    }\r
+\r
+    Str++;\r
+  }\r
+\r
+  return Number;\r
+}\r
+\r
+\r
+/*++\r
+\r
+This function extends the capability of SetFilePointer to accept 64 bit parameters\r
+\r
+**/\r
+EFI_STATUS\r
+SetFilePointer64 (\r
+  IN  EMU_BLOCK_IO_PRIVATE    *Private,\r
+  IN  INT64                      DistanceToMove,\r
+  OUT UINT64                     *NewFilePointer,\r
+  IN  INT32                      MoveMethod\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  off_t         res;\r
+\r
+  Status = EFI_SUCCESS;\r
+  res = Private->UnixThunk->Lseek(Private->fd, DistanceToMove, MoveMethod);\r
+  if (res == -1) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (NewFilePointer != NULL) {\r
+    *NewFilePointer = res;\r
+  }\r
+\r
+  return Status;\r
+}\r
index c00268b3831959e7fd0162d5fb1b6bf729615e7e..9c0990b2cdf173765175b0b686df07e15414bf92 100644 (file)
@@ -458,7 +458,6 @@ SecLoadFromCore (
     (SWITCH_STACK_ENTRY_POINT) (UINTN) PeiCoreEntryPoint,
     SecCoreData,
     (VOID *)gPpiList,
-    NULL,
     TopOfStack
     );
   //
index 00ab7a61ab3648d97f6aec6d76efd574b44d546e..19e5f17147644825d83bad4e208173d87b1b4569 100644 (file)
@@ -283,7 +283,6 @@ PeiSwitchStacks (
   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,\r
   IN      VOID                      *Context1,  OPTIONAL\r
   IN      VOID                      *Context2,  OPTIONAL\r
-  IN      VOID                      *Context3,  OPTIONAL\r
   IN      VOID                      *NewStack\r
   );\r
 \r
index 76567ac0e178f2870105cf046cc99ae71bceb1b9..8a57b781b54045bb640487bdde6ca29bf4659e26 100644 (file)
@@ -16,7 +16,7 @@
 #------------------------------------------------------------------------------\r
 # Routine Description:\r
 #\r
-#   Routine for switching stacks with 3 parameters EFI ABI\r
+#   Routine for switching stacks with 2 parameters EFI ABI\r
 #   Convert UNIX to EFI ABI\r
 #\r
 # Arguments:\r
@@ -24,8 +24,7 @@
 #   (rdi) EntryPoint    - Entry point with new stack.\r
 #   (rsi) Context1      - Parameter1 for entry point. (rcx)\r
 #   (rdx) Context2      - Parameter2 for entry point. (rdx) \r
-#   (rcx) Context3      - Parameter3 for entry point. (r8)\r
-#   (r8)  NewStack      - The pointer to new stack.\r
+#   (rcx) NewStack      - The pointer to new stack.\r
 #\r
 # Returns:\r
 #\r
@@ -37,11 +36,11 @@ ASM_PFX(PeiSwitchStacks):
     pushq   $0            // tells gdb to stop unwinding frame\r
     movq    %rsp, %rbp\r
 \r
-    movq    %r8,  %rsp\r
+    movq    %rcx, %rsp    // update stack pointer\r
     \r
-    movq    %rdi, %rax\r
-    movq    %rsi, %rcx\r
-    movq    %rcx, %r8    \r
+    movq    %rdi, %rax    // entry point to %rax\r
+    movq    %rsi, %rcx    // Adjust Context1\r
+                          // Context2 already in the rigth spot\r
     \r
     #\r
     # Reserve space for register parameters (rcx, rdx, r8 & r9) on the stack,\r
index dcae0176ff51c3aa18aa0a3350ff1a89772edbd2..06b7b343228989ce0dc5b665be122b4e0934555f 100644 (file)
   InOsEmuPkg/EmuBusDriverDxe/EmuBusDriverDxe.inf\r
   InOsEmuPkg/EmuGopDxe/EmuGopDxe.inf\r
   InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystemDxe.inf\r
+  InOsEmuPkg/EmuBlockIoDxe/EmuBlockIoDxe.inf\r
 \r
 !if $(0)\r
-  UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf\r
   UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf\r
   UnixPkg/UnixConsoleDxe/UnixConsole.inf\r
   UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf\r
index 0ba58a39d092f6ab936667794d903a9ee40e7637..14e5b6022a7d5bbd2588147d855712b525ee9531 100644 (file)
@@ -253,24 +253,18 @@ INF  MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
 INF FatPkg/EnhancedFatDxe/Fat.inf\r
 !else\r
 # Used checked in Visual Studio binaries\r
-INF  RuleOverride = BINARY USE = X64 FatBinPkg/EnhancedFatDxe/Fat.inf\r
+FILE DRIVER = 961578FE-B6B7-44c3-AF35-6BC705CD2B1F {\r
+    SECTION PE32 = FatBinPkg/EnhancedFatDxe/X64/Fat.efi\r
+  }\r
 !endif\r
 \r
 !if $(BUILD_NEW_SHELL)\r
 INF  ShellPkg/Application/Shell/Shell.inf\r
 !else\r
-!if $(USE_NEW_SHELL)\r
-INF  ShellBinPkg/UefiShell/UefiShell.inf\r
-!else\r
- FILE APPLICATION = PCD(gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile) {\r
-!if $(BUILD_OLD_SHELL)\r
-  SECTION PE32 = Build/GccShellPkg/DEBUG_XCLANG/X64/ShellFull.efi\r
-!else\r
-  SECTION PE32 = EdkShellBinPkg/FullShell/X64/Shell_Full.efi\r
-!endif\r
-  SECTION UI = "Shell"\r
- }\r
-!endif\r
+# Used checked in Visual Studio binaries\r
+FILE APPLICATION = PCD(gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile) {\r
+    SECTION PE32 = EdkShellBinPkg/FullShell/X64/Shell_Full.efi\r
+  }\r
 !endif\r
 \r
 FILE FREEFORM = PCD(gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile) {\r
index e575a9266ee09d15bc9cda15d8e3b2dce2038b16..a9294be02e77d0dc09cceee3d405a447e440a91c 100755 (executable)
@@ -43,7 +43,8 @@ fi
 TARGET_TOOLS=MYTOOLS
 UNIXPKG_TOOLS=GCC44
 NETWORK_SUPPORT=
-COMPILE_BINS=
+BUILD_NEW_SHELL=
+BUILD_FAT=
 case `uname` in
   CYGWIN*) echo Cygwin not fully supported yet. ;;
   Darwin*)
@@ -56,8 +57,9 @@ case `uname` in
         TARGET_TOOLS=XCODE32
         UNIXPKG_TOOLS=XCLANG
       fi
-      NETWORK_SUPPORT="-D NETWORK_SUPPORT"
-      COMPILE_BINS="-D COMPILE_BINS"
+#      NETWORK_SUPPORT="-D NETWORK_SUPPORT"
+#      BUILD_NEW_SHELL="-D BUILD_NEW_SHELL"
+#      BUILD_FAT="-D BUILD_FAT"
       ;;
   Linux*) TARGET_TOOLS=ELFGCC ;;
 
@@ -112,11 +114,6 @@ do
     exit $?
   fi
 
-  if [[ $arg == shell ]]; then
-    build -p $WORKSPACE/ShellPkg/ShellPkg.dsc -a X64 -t $UNIXPKG_TOOLS -n 3 $2 $3 $4 $5 $6 $7 $8
-    cp Build/Shell/DEBUG_$UNIXPKG_TOOLS/X64/Shell.efi ShellBinPkg/UefiShell/X64/Shell.efi
-    exit $?
-  fi
 done
 
 
@@ -126,7 +123,7 @@ done
 echo $PATH
 echo `which build`
 build -p $WORKSPACE/InOsEmuPkg/Unix/UnixX64.dsc      -a X64 -t $TARGET_TOOLS -D SEC_ONLY -n 3 $1 $2 $3 $4 $5 $6 $7 $8  modules
-build -p $WORKSPACE/InOsEmuPkg/Unix/UnixX64.dsc      -a X64 -t $UNIXPKG_TOOLS $NETWORK_SUPPORT -n 3 $1 $2 $3 $4 $5 $6 $7 $8
+build -p $WORKSPACE/InOsEmuPkg/Unix/UnixX64.dsc      -a X64 -t $UNIXPKG_TOOLS $NETWORK_SUPPORT $BUILD_NEW_SHELL $BUILD_FAT -n 3 $1 $2 $3 $4 $5 $6 $7 $8
 cp $WORKSPACE/Build/EmuUnixX64/DEBUG_"$TARGET_TOOLS"/X64/SecMain $WORKSPACE/Build/EmuUnixX64/DEBUG_"$UNIXPKG_TOOLS"/X64
 exit $?