summaryrefslogtreecommitdiff
path: root/UnixPkg/UnixBlockIoDxe
diff options
context:
space:
mode:
authoreric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>2008-06-30 05:08:49 +0000
committereric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>2008-06-30 05:08:49 +0000
commit804405e7d10525e41720216137b2551f62a0663f (patch)
treea615301e36e63aba81adcb0a963e4d3aa7830863 /UnixPkg/UnixBlockIoDxe
parent27d55a2d56320e6e7a1dda2b02089721540d6bc3 (diff)
downloadedk2-platforms-804405e7d10525e41720216137b2551f62a0663f.tar.xz
Port EdkUnixPkg to UnixPkg. The changes are listed as follows:
1. change *.msa to *.inf, and create platform configuration files .dec&.dsc&.fdf to comply with Edk2 build process 2. using PCD mechanism to replace macro. 3. change Sec code to cowork with PI1.0 Pei Core and produce temparory memory ppi. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5380 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'UnixPkg/UnixBlockIoDxe')
-rw-r--r--UnixPkg/UnixBlockIoDxe/ComponentName.c197
-rw-r--r--UnixPkg/UnixBlockIoDxe/DriverConfiguration.c338
-rw-r--r--UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c187
-rw-r--r--UnixPkg/UnixBlockIoDxe/EntryPoint.c51
-rw-r--r--UnixPkg/UnixBlockIoDxe/UnixBlockIo.c1307
-rw-r--r--UnixPkg/UnixBlockIoDxe/UnixBlockIo.h219
-rw-r--r--UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf71
-rw-r--r--UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa91
8 files changed, 2461 insertions, 0 deletions
diff --git a/UnixPkg/UnixBlockIoDxe/ComponentName.c b/UnixPkg/UnixBlockIoDxe/ComponentName.c
new file mode 100644
index 0000000000..19085fd88a
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/ComponentName.c
@@ -0,0 +1,197 @@
+/*++
+
+Copyright (c) 2004, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+ ComponentName.c
+
+Abstract:
+
+--*/
+
+#include "UnixBlockIo.h"
+
+//
+// EFI Component Name Functions
+//
+EFI_STATUS
+EFIAPI
+UnixBlockIoComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ );
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ );
+
+//
+// EFI Component Name Protocol
+//
+EFI_COMPONENT_NAME_PROTOCOL gUnixBlockIoComponentName = {
+ UnixBlockIoComponentNameGetDriverName,
+ UnixBlockIoComponentNameGetControllerName,
+ "eng"
+};
+
+static EFI_UNICODE_STRING_TABLE mUnixBlockIoDriverNameTable[] = {
+ { "eng", L"Unix Block I/O Driver" },
+ { NULL , NULL }
+};
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ Language - A pointer to a three character ISO 639-2 language identifier.
+ This is the language of the driver name that that the caller
+ is requesting, and it must match one of the languages specified
+ in SupportedLanguages. The number of languages supported by a
+ driver is up to the driver writer.
+ DriverName - A pointer to the Unicode string to return. This Unicode string
+ is the name of the driver specified by This in the language
+ specified by Language.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the Driver specified by This
+ and the language specified by Language was returned
+ in DriverName.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - DriverName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ return LookupUnicodeString (
+ Language,
+ gUnixBlockIoComponentName.SupportedLanguages,
+ mUnixBlockIoDriverNameTable,
+ DriverName
+ );
+}
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by an EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ ControllerHandle - The handle of a controller that the driver specified by
+ This is managing. This handle specifies the controller
+ whose name is to be returned.
+ ChildHandle - The handle of the child controller to retrieve the name
+ of. 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 retrieve the name of the
+ bus controller. It will not be NULL for a bus driver
+ that wishes to retrieve the name of a child controller.
+ Language - A pointer to a three character ISO 639-2 language
+ identifier. This is the language of the controller name
+ that that the caller is requesting, and it must match one
+ of the languages specified in SupportedLanguages. The
+ number of languages supported by a driver is up to the
+ driver writer.
+ ControllerName - A pointer to the Unicode string to return. This Unicode
+ string is the name of the controller specified by
+ ControllerHandle and ChildHandle in the language specified
+ by Language from the point of view of the driver specified
+ by This.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the user readable name in the
+ language specified by Language for the driver
+ specified by This was returned in DriverName.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - ControllerName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This is not currently managing
+ the controller specified by ControllerHandle and
+ ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ UNIX_BLOCK_IO_PRIVATE *Private;
+
+ //
+ // This is a device driver, so ChildHandle must be NULL.
+ //
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Make sure this driver is currently managing ControllerHandle
+ //
+ Status = EfiTestManagedDevice (
+ ControllerHandle,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ &gEfiUnixIoProtocolGuid
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Get our context back
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiBlockIoProtocolGuid,
+ (void *)&BlockIo,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);
+
+ return LookupUnicodeString (
+ Language,
+ gUnixBlockIoComponentName.SupportedLanguages,
+ Private->ControllerNameTable,
+ ControllerName
+ );
+}
diff --git a/UnixPkg/UnixBlockIoDxe/DriverConfiguration.c b/UnixPkg/UnixBlockIoDxe/DriverConfiguration.c
new file mode 100644
index 0000000000..d06b5fba4d
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/DriverConfiguration.c
@@ -0,0 +1,338 @@
+/*++
+
+Copyright (c) 2004 - 2005, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+ DriverConfiguration.c
+
+Abstract:
+
+--*/
+
+#include "UnixBlockIo.h"
+
+//
+// EFI Driver Configuration Functions
+//
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationSetOptions (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
+ );
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationOptionsValid (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL
+ );
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationForceDefaults (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN UINT32 DefaultType,
+ OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
+ );
+
+//
+// EFI Driver Configuration Protocol
+//
+EFI_DRIVER_CONFIGURATION_PROTOCOL gUnixBlockIoDriverConfiguration = {
+ UnixBlockIoDriverConfigurationSetOptions,
+ UnixBlockIoDriverConfigurationOptionsValid,
+ UnixBlockIoDriverConfigurationForceDefaults,
+ LANGUAGESUPPORTED
+};
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationSetOptions (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
+ )
+/*++
+
+ Routine Description:
+ Allows the user to set controller specific options for a controller that a
+ driver is currently managing.
+
+ Arguments:
+ This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
+ ControllerHandle - The handle of the controller to set options on.
+ ChildHandle - The handle of the child controller to set options on. This
+ is an optional parameter that may be NULL. It will be NULL
+ for device drivers, and for a bus drivers that wish to set
+ options for the bus controller. It will not be NULL for a
+ bus driver that wishes to set options for one of its child
+ controllers.
+ Language - A pointer to a three character ISO 639-2 language identifier.
+ This is the language of the user interface that should be
+ presented to the user, and it must match one of the languages
+ specified in SupportedLanguages. The number of languages
+ supported by a driver is up to the driver writer.
+ ActionRequired - A pointer to the action that the calling agent is required
+ to perform when this function returns. See "Related
+ Definitions" for a list of the actions that the calling
+ agent is required to perform prior to accessing
+ ControllerHandle again.
+
+ Returns:
+ EFI_SUCCESS - The driver specified by This successfully set the
+ configuration options for the controller specified
+ by ControllerHandle..
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ActionRequired is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support setting
+ configuration options for the controller specified by
+ ControllerHandle and ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+ EFI_DEVICE_ERROR - A device error occurred while attempt to set the
+ configuration options for the controller specified
+ by ControllerHandle and ChildHandle.
+ EFI_OUT_RESOURCES - There are not enough resources available to set the
+ configuration options for the controller specified
+ by ControllerHandle and ChildHandle.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ CHAR8 *SupportedLanguage;
+
+ SupportedLanguage = This->SupportedLanguages;
+
+ Status = EFI_UNSUPPORTED;
+ while (*SupportedLanguage != 0) {
+ if (AsciiStrnCmp (Language, SupportedLanguage, 3)) {
+ Status = EFI_SUCCESS;
+ }
+
+ SupportedLanguage += 3;
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (ActionRequired == NULL || ControllerHandle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Validate controller handle
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&BlockIo,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+
+ if (!EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle
+ );
+
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Status == EFI_UNSUPPORTED) {
+ return Status;
+ } else if (Status != EFI_ALREADY_STARTED) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *ActionRequired = EfiDriverConfigurationActionNone;
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationOptionsValid (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL
+ )
+/*++
+
+ Routine Description:
+ Tests to see if a controller's current configuration options are valid.
+
+ Arguments:
+ This - A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.
+ ControllerHandle - The handle of the controller to test if it's current
+ configuration options are valid.
+ ChildHandle - The handle of the child controller to test if it's current
+ configuration options are valid. 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 test the configuration options for the bus controller.
+ It will not be NULL for a bus driver that wishes to test
+ configuration options for one of its child controllers.
+
+ Returns:
+ EFI_SUCCESS - The controller specified by ControllerHandle and
+ ChildHandle that is being managed by the driver
+ specified by This has a valid set of configuration
+ options.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_UNSUPPORTED - The driver specified by This is not currently
+ managing the controller specified by ControllerHandle
+ and ChildHandle.
+ EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
+ ChildHandle that is being managed by the driver
+ specified by This has an invalid set of configuration
+ options.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if (ControllerHandle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Validate controller handle
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&BlockIo,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+
+ if (!EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle
+ );
+
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Status == EFI_UNSUPPORTED) {
+ return Status;
+ } else if (Status != EFI_ALREADY_STARTED) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationForceDefaults (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN UINT32 DefaultType,
+ OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
+ )
+/*++
+
+ Routine Description:
+ Forces a driver to set the default configuration options for a controller.
+
+ Arguments:
+ This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
+ ControllerHandle - The handle of the controller to force default configuration options on.
+ 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.
+ 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.
+ 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.
+
+ Returns:
+ EFI_SUCCESS - The driver specified by This successfully forced the default configuration options on the controller specified by ControllerHandle and ChildHandle.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ActionRequired is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support forcing the default configuration options on the controller specified by ControllerHandle and ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the configuration type specified by DefaultType.
+ EFI_DEVICE_ERROR - A device error occurred while attempt to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.
+ EFI_OUT_RESOURCES - There are not enough resources available to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if (ActionRequired == NULL || ControllerHandle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Validate controller handle
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&BlockIo,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+
+ if (!EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle
+ );
+
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Status == EFI_UNSUPPORTED) {
+ return Status;
+ } else if (Status != EFI_ALREADY_STARTED) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *ActionRequired = EfiDriverConfigurationActionNone;
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c b/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c
new file mode 100644
index 0000000000..0e9a32c66a
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c
@@ -0,0 +1,187 @@
+/*++
+
+Copyright (c) 2004 - 2005, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+ DriverDiagnostics.c
+
+Abstract:
+
+--*/
+
+#include "UnixBlockIo.h"
+
+//
+// EFI Driver Diagnostics Functions
+//
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverDiagnosticsRunDiagnostics (
+ IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,
+ IN CHAR8 *Language,
+ OUT EFI_GUID **ErrorType,
+ OUT UINTN *BufferSize,
+ OUT CHAR16 **Buffer
+ );
+
+//
+// EFI Driver Diagnostics Protocol
+//
+EFI_DRIVER_DIAGNOSTICS_PROTOCOL gUnixBlockIoDriverDiagnostics = {
+ UnixBlockIoDriverDiagnosticsRunDiagnostics,
+ LANGUAGESUPPORTED
+};
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverDiagnosticsRunDiagnostics (
+ IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,
+ IN CHAR8 *Language,
+ OUT EFI_GUID **ErrorType,
+ OUT UINTN *BufferSize,
+ OUT CHAR16 **Buffer
+ )
+/*++
+
+ Routine Description:
+ Runs diagnostics on a controller.
+
+ Arguments:
+ This - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.
+ ControllerHandle - The handle of the controller to run diagnostics on.
+ ChildHandle - The handle of the child controller to run diagnostics 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 run diagnostics on the bus
+ controller. It will not be NULL for a bus driver that
+ wishes to run diagnostics on one of its child controllers.
+ DiagnosticType - Indicates type of diagnostics to perform on the controller
+ specified by ControllerHandle and ChildHandle. See
+ "Related Definitions" for the list of supported types.
+ Language - A pointer to a three character ISO 639-2 language
+ identifier. This is the language in which the optional
+ error message should be returned in Buffer, and it must
+ match one of the languages specified in SupportedLanguages.
+ The number of languages supported by a driver is up to
+ the driver writer.
+ ErrorType - A GUID that defines the format of the data returned in
+ Buffer.
+ BufferSize - The size, in bytes, of the data returned in Buffer.
+ Buffer - A buffer that contains a Null-terminated Unicode string
+ plus some additional data whose format is defined by
+ ErrorType. Buffer is allocated by this function with
+ AllocatePool(), and it is the caller's responsibility
+ to free it with a call to FreePool().
+
+ Returns:
+ EFI_SUCCESS - The controller specified by ControllerHandle and
+ ChildHandle passed the diagnostic.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid
+ EFI_HANDLE.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - ErrorType is NULL.
+ EFI_INVALID_PARAMETER - BufferType is NULL.
+ EFI_INVALID_PARAMETER - Buffer is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support
+ running diagnostics for the controller specified
+ by ControllerHandle and ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ type of diagnostic specified by DiagnosticType.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+ EFI_OUT_OF_RESOURCES - There are not enough resources available to complete
+ the diagnostics.
+ EFI_OUT_OF_RESOURCES - There are not enough resources available to return
+ the status information in ErrorType, BufferSize,
+ and Buffer.
+ EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
+ ChildHandle did not pass the diagnostic.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ CHAR8 *SupportedLanguage;
+
+ if (Language == NULL ||
+ ErrorType == NULL ||
+ Buffer == NULL ||
+ ControllerHandle == NULL ||
+ BufferSize == NULL) {
+
+ return EFI_INVALID_PARAMETER;
+ }
+
+ SupportedLanguage = This->SupportedLanguages;
+
+ Status = EFI_UNSUPPORTED;
+ while (*SupportedLanguage != 0) {
+ if (AsciiStrnCmp (Language, SupportedLanguage, 3)) {
+ Status = EFI_SUCCESS;
+ break;
+ }
+
+ SupportedLanguage += 3;
+ }
+
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ *ErrorType = NULL;
+ *BufferSize = 0;
+ if (DiagnosticType != EfiDriverDiagnosticTypeStandard) {
+ *ErrorType = &gEfiBlockIoProtocolGuid;
+ *BufferSize = 0x60;
+ gBS->AllocatePool (EfiBootServicesData, (UINTN) (*BufferSize),
+ (void *)Buffer);
+ CopyMem (*Buffer, L"Unix Block I/O Driver Diagnostics Failed\n", *BufferSize);
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Validate controller handle
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&BlockIo,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+
+ if (!EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle
+ );
+
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Status == EFI_UNSUPPORTED) {
+ return Status;
+ } else if (Status != EFI_ALREADY_STARTED) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/UnixBlockIoDxe/EntryPoint.c b/UnixPkg/UnixBlockIoDxe/EntryPoint.c
new file mode 100644
index 0000000000..dae3687906
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/EntryPoint.c
@@ -0,0 +1,51 @@
+/**@file
+ Entry Point Source file.
+
+ This file contains the user entry point
+
+ Copyright (c) 2006 - 2008, Intel Corporation
+ All rights reserved. This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+
+
+#include "UnixBlockIo.h"
+
+/**
+ The user Entry Point for module UnixBlockIo. The user code starts with this function.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeUnixBlockIo(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = EfiLibInstallAllDriverProtocols (
+ ImageHandle,
+ SystemTable,
+ &gUnixBlockIoDriverBinding,
+ ImageHandle,
+ &gUnixBlockIoComponentName,
+ NULL,
+ &gUnixBlockIoDriverDiagnostics
+ );
+ ASSERT_EFI_ERROR (Status);
+
+
+ return Status;
+}
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c
new file mode 100644
index 0000000000..d92ab7251c
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c
@@ -0,0 +1,1307 @@
+/*++
+
+Copyright (c) 2004 - 2007, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+ UnixBlockIo.c
+
+Abstract:
+
+ Produce block IO abstractions for real devices on your PC using Posix APIs.
+ The configuration of what devices to mount or emulate comes from UNIX
+ environment variables. The variables must be visible to the Microsoft*
+ Developer Studio for them to work.
+
+ <F>ixed - Fixed disk like a hard drive.
+ <R>emovable - Removable media like a floppy or CD-ROM.
+ Read <O>nly - Write protected device.
+ Read <W>rite - Read write device.
+ <block count> - Decimal number of blocks a device supports.
+ <block size> - Decimal number of bytes per block.
+
+ UNIX envirnonment variable contents. '<' and '>' are not part of the variable,
+ they are just used to make this help more readable. There should be no
+ spaces between the ';'. Extra spaces will break the variable. A '!' is
+ used to seperate multiple devices in a variable.
+
+ EFI_UNIX_VIRTUAL_DISKS =
+ <F | R><O | W>;<block count>;<block size>[!...]
+
+ EFI_UNIX_PHYSICAL_DISKS =
+ <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]
+
+ Virtual Disks: These devices use a file to emulate a hard disk or removable
+ media device.
+
+ Thus a 20 MB emulated hard drive would look like:
+ EFI_UNIX_VIRTUAL_DISKS=FW;40960;512
+
+ A 1.44MB emulated floppy with a block size of 1024 would look like:
+ EFI_UNIX_VIRTUAL_DISKS=RW;1440;1024
+
+ Physical Disks: These devices use UNIX to open a real device in your system
+
+ Thus a 120 MB floppy would look like:
+ EFI_UNIX_PHYSICAL_DISKS=B:RW;245760;512
+
+ Thus a standard CD-ROM floppy would look like:
+ EFI_UNIX_PHYSICAL_DISKS=Z:RO;307200;2048
+
+
+ * Other names and brands may be claimed as the property of others.
+
+--*/
+
+#include <fcntl.h>
+#include <unistd.h>
+#include "UnixBlockIo.h"
+
+//
+// Block IO protocol member functions
+//
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoReadBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ MediaId - TODO: add argument description
+ Lba - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoWriteBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ MediaId - TODO: add argument description
+ Lba - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoFlushBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoResetBlock (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ ExtendedVerification - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+//
+// Private Worker functions
+//
+STATIC
+EFI_STATUS
+UnixBlockIoCreateMapping (
+ IN EFI_UNIX_IO_PROTOCOL *UnixIo,
+ IN EFI_HANDLE EfiDeviceHandle,
+ IN CHAR16 *Filename,
+ IN BOOLEAN ReadOnly,
+ IN BOOLEAN RemovableMedia,
+ IN UINTN NumberOfBlocks,
+ IN UINTN BlockSize
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ UnixIo - TODO: add argument description
+ EfiDeviceHandle - TODO: add argument description
+ Filename - TODO: add argument description
+ ReadOnly - TODO: add argument description
+ RemovableMedia - TODO: add argument description
+ NumberOfBlocks - TODO: add argument description
+ BlockSize - TODO: add argument description
+ DeviceType - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+UnixBlockIoReadWriteCommon (
+ IN UNIX_BLOCK_IO_PRIVATE *Private,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ IN VOID *Buffer,
+ IN CHAR8 *CallerName
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+ MediaId - TODO: add argument description
+ Lba - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+ CallerName - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+UnixBlockIoError (
+ IN UNIX_BLOCK_IO_PRIVATE *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+UnixBlockIoOpenDevice (
+ UNIX_BLOCK_IO_PRIVATE *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+CHAR16 *
+GetNextElementPastTerminator (
+ IN CHAR16 *EnvironmentVariable,
+ IN CHAR16 Terminator
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ EnvironmentVariable - TODO: add argument description
+ Terminator - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+EFI_DRIVER_BINDING_PROTOCOL gUnixBlockIoDriverBinding = {
+ UnixBlockIoDriverBindingSupported,
+ UnixBlockIoDriverBindingStart,
+ UnixBlockIoDriverBindingStop,
+ 0xa,
+ NULL,
+ NULL
+};
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: Handle - add argument and description to function comment
+// TODO: RemainingDevicePath - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+
+ //
+ // Open the IO Abstraction(s) needed to perform the supported test
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID **)&UnixIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Make sure the UnixThunkProtocol is valid
+ //
+ Status = EFI_UNSUPPORTED;
+ if (UnixIo->UnixThunk->Signature == EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {
+
+ //
+ // Check the GUID to see if this is a handle type the driver supports
+ //
+ if (CompareGuid (UnixIo->TypeGuid, &gEfiUnixVirtualDisksGuid) ) {
+ Status = EFI_SUCCESS;
+ }
+ }
+
+ //
+ // Close the I/O Abstraction(s) used to perform the supported test
+ //
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: Handle - add argument and description to function comment
+// TODO: RemainingDevicePath - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+ CHAR16 Buffer[FILENAME_BUFFER_SIZE];
+ CHAR16 *Str;
+ BOOLEAN RemovableMedia;
+ BOOLEAN WriteProtected;
+ UINTN NumberOfBlocks;
+ UINTN BlockSize;
+ INTN i;
+
+ //
+ // Grab the protocols we need
+ //
+
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&UnixIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ //
+ // Set DiskType
+ //
+ if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixVirtualDisksGuid)) {
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ Status = EFI_NOT_FOUND;
+ // Extract filename.
+ Str = UnixIo->EnvString;
+ i = 0;
+ while (*Str && *Str != ':')
+ Buffer[i++] = *Str++;
+ Buffer[i] = 0;
+ if (*Str != ':') {
+ goto Done;
+ }
+
+ Str++;
+
+ RemovableMedia = FALSE;
+ WriteProtected = TRUE;
+ NumberOfBlocks = 0;
+ BlockSize = 512;
+ do {
+ if (*Str == 'R' || *Str == 'F') {
+ RemovableMedia = (BOOLEAN) (*Str == 'R');
+ Str++;
+ }
+ if (*Str == 'O' || *Str == 'W') {
+ WriteProtected = (BOOLEAN) (*Str == 'O');
+ Str++;
+ }
+ if (*Str == 0)
+ break;
+ if (*Str != ';')
+ goto Done;
+ Str++;
+
+ NumberOfBlocks = Atoi (Str);
+ Str = GetNextElementPastTerminator (Str, ';');
+ if (NumberOfBlocks == 0)
+ break;
+
+ BlockSize = Atoi (Str);
+ if (BlockSize != 0)
+ Str = GetNextElementPastTerminator (Str, ';');
+ } while (0);
+
+ //
+ // If we get here the variable is valid so do the work.
+ //
+ Status = UnixBlockIoCreateMapping (
+ UnixIo,
+ Handle,
+ Buffer,
+ WriteProtected,
+ RemovableMedia,
+ NumberOfBlocks,
+ BlockSize
+ );
+
+Done:
+ if (EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+ }
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Handle - TODO: add argument description
+ NumberOfChildren - TODO: add argument description
+ ChildHandleBuffer - TODO: add argument description
+
+Returns:
+
+ EFI_UNSUPPORTED - TODO: Add description for return value
+
+--*/
+{
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ EFI_STATUS Status;
+ UNIX_BLOCK_IO_PRIVATE *Private;
+
+ //
+ // Get our context back
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiBlockIoProtocolGuid,
+ (void *)&BlockIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);
+
+ //
+ // BugBug: If we need to kick people off, we need to make Uninstall Close the handles.
+ // We could pass in our image handle or FLAG our open to be closed via
+ // Unistall (== to saying any CloseProtocol will close our open)
+ //
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ Private->EfiHandle,
+ &gEfiBlockIoProtocolGuid,
+ &Private->BlockIo,
+ NULL
+ );
+ if (!EFI_ERROR (Status)) {
+
+ Status = gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+
+ //
+ // Shut down our device
+ //
+ Private->UnixThunk->Close (Private->fd);
+
+ //
+ // Free our instance data
+ //
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+
+ gBS->FreePool (Private);
+ }
+
+ return Status;
+}
+
+STATIC
+CHAR16 *
+GetNextElementPastTerminator (
+ IN CHAR16 *EnvironmentVariable,
+ IN CHAR16 Terminator
+ )
+/*++
+
+Routine Description:
+
+ Worker function to parse environment variables.
+
+Arguments:
+ EnvironmentVariable - Envirnment variable to parse.
+
+ Terminator - Terminator to parse for.
+
+Returns:
+
+ Pointer to next eliment past the first occurence of Terminator or the '\0'
+ at the end of the string.
+
+--*/
+{
+ CHAR16 *Ptr;
+
+ for (Ptr = EnvironmentVariable; *Ptr != '\0'; Ptr++) {
+ if (*Ptr == Terminator) {
+ Ptr++;
+ break;
+ }
+ }
+
+ return Ptr;
+}
+
+STATIC
+EFI_STATUS
+UnixBlockIoCreateMapping (
+ IN EFI_UNIX_IO_PROTOCOL *UnixIo,
+ IN EFI_HANDLE EfiDeviceHandle,
+ IN CHAR16 *Filename,
+ IN BOOLEAN ReadOnly,
+ IN BOOLEAN RemovableMedia,
+ IN UINTN NumberOfBlocks,
+ IN UINTN BlockSize
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ UnixIo - TODO: add argument description
+ EfiDeviceHandle - TODO: add argument description
+ Filename - TODO: add argument description
+ ReadOnly - TODO: add argument description
+ RemovableMedia - TODO: add argument description
+ NumberOfBlocks - TODO: add argument description
+ BlockSize - TODO: add argument description
+ DeviceType - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ UNIX_BLOCK_IO_PRIVATE *Private;
+ UINTN Index;
+
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ sizeof (UNIX_BLOCK_IO_PRIVATE),
+ (void *)&Private
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ EfiInitializeLock (&Private->Lock, TPL_NOTIFY);
+
+ Private->UnixThunk = UnixIo->UnixThunk;
+
+ Private->Signature = UNIX_BLOCK_IO_PRIVATE_SIGNATURE;
+ Private->LastBlock = NumberOfBlocks - 1;
+ Private->BlockSize = BlockSize;
+
+ for (Index = 0; Filename[Index] != 0; Index++) {
+ Private->Filename[Index] = Filename[Index];
+ }
+
+ Private->Filename[Index] = 0;
+
+ Private->Mode = (ReadOnly ? O_RDONLY : O_RDWR);
+
+ Private->NumberOfBlocks = NumberOfBlocks;
+ Private->fd = -1;
+
+ Private->ControllerNameTable = NULL;
+
+ AddUnicodeString (
+ "eng",
+ gUnixBlockIoComponentName.SupportedLanguages,
+ &Private->ControllerNameTable,
+ Filename
+ );
+
+ BlockIo = &Private->BlockIo;
+ BlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION;
+ BlockIo->Media = &Private->Media;
+ BlockIo->Media->BlockSize = Private->BlockSize;
+ BlockIo->Media->LastBlock = Private->NumberOfBlocks - 1;
+ BlockIo->Media->MediaId = 0;;
+
+ BlockIo->Reset = UnixBlockIoResetBlock;
+ BlockIo->ReadBlocks = UnixBlockIoReadBlocks;
+ BlockIo->WriteBlocks = UnixBlockIoWriteBlocks;
+ BlockIo->FlushBlocks = UnixBlockIoFlushBlocks;
+
+ BlockIo->Media->ReadOnly = ReadOnly;
+ BlockIo->Media->RemovableMedia = RemovableMedia;
+ BlockIo->Media->LogicalPartition = FALSE;
+ BlockIo->Media->MediaPresent = TRUE;
+ BlockIo->Media->WriteCaching = FALSE;
+
+ BlockIo->Media->IoAlign = 1;
+
+ Private->EfiHandle = EfiDeviceHandle;
+ Status = UnixBlockIoOpenDevice (Private);
+ if (!EFI_ERROR (Status)) {
+
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Private->EfiHandle,
+ &gEfiBlockIoProtocolGuid,
+ &Private->BlockIo,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+ gBS->FreePool (Private);
+ }
+
+ DEBUG ((EFI_D_ERROR, "BlockDevice added: %s\n", Filename));
+ }
+
+ return Status;
+}
+
+STATIC
+EFI_STATUS
+UnixBlockIoOpenDevice (
+ UNIX_BLOCK_IO_PRIVATE *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ EFI_STATUS Status;
+ UINT64 FileSize;
+ UINT64 EndOfFile;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+
+ BlockIo = &Private->BlockIo;
+ EfiAcquireLock (&Private->Lock);
+
+ //
+ // If the device is already opened, close it
+ //
+ if (Private->fd >= 0) {
+ BlockIo->Reset (BlockIo, FALSE);
+ }
+
+ //
+ // Open the device
+ //
+ Private->fd = Private->UnixThunk->Open
+ (Private->Filename, Private->Mode, 0644);
+
+ if (Private->fd < 0) {
+ DEBUG ((EFI_D_INFO, "PlOpenBlock: Could not open %s\n",
+ Private->Filename));
+ BlockIo->Media->MediaPresent = FALSE;
+ Status = EFI_NO_MEDIA;
+ goto Done;
+ }
+
+ if (!BlockIo->Media->MediaPresent) {
+ //
+ // BugBug: try to emulate if a CD appears - notify drivers to check it out
+ //
+ BlockIo->Media->MediaPresent = TRUE;
+ EfiReleaseLock (&Private->Lock);
+ EfiAcquireLock (&Private->Lock);
+ }
+
+ //
+ // get the size of the file
+ //
+ Status = SetFilePointer64 (Private, 0, &FileSize, SEEK_END);
+
+ if (EFI_ERROR (Status)) {
+ FileSize = MultU64x32 (Private->NumberOfBlocks, Private->BlockSize);
+ DEBUG ((EFI_D_ERROR, "PlOpenBlock: Could not get filesize of %s\n", Private->Filename));
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ if (Private->NumberOfBlocks == 0) {
+ Private->NumberOfBlocks = DivU64x32 (FileSize, Private->BlockSize);
+ }
+
+ EndOfFile = MultU64x32 (Private->NumberOfBlocks, Private->BlockSize);
+
+ if (FileSize != EndOfFile) {
+ //
+ // file is not the proper size, change it
+ //
+ DEBUG ((EFI_D_INIT, "PlOpenBlock: Initializing block device: %a\n", Private->Filename));
+
+ //
+ // first set it to 0
+ //
+ Private->UnixThunk->FTruncate (Private->fd, 0);
+
+ //
+ // then set it to the needed file size (OS will zero fill it)
+ //
+ Private->UnixThunk->FTruncate (Private->fd, EndOfFile);
+ }
+
+ DEBUG ((EFI_D_INIT, "%HPlOpenBlock: opened %s%N\n", Private->Filename));
+ Status = EFI_SUCCESS;
+
+Done:
+ if (EFI_ERROR (Status)) {
+ if (Private->fd >= 0) {
+ BlockIo->Reset (BlockIo, FALSE);
+ }
+ }
+
+ EfiReleaseLock (&Private->Lock);
+ return Status;
+}
+
+STATIC
+EFI_STATUS
+UnixBlockIoError (
+ IN UNIX_BLOCK_IO_PRIVATE *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ return EFI_DEVICE_ERROR;
+
+#if 0
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ EFI_STATUS Status;
+ BOOLEAN ReinstallBlockIoFlag;
+
+
+ BlockIo = &Private->BlockIo;
+
+ switch (Private->UnixThunk->GetLastError ()) {
+
+ case ERROR_NOT_READY:
+ Status = EFI_NO_MEDIA;
+ BlockIo->Media->ReadOnly = FALSE;
+ BlockIo->Media->MediaPresent = FALSE;
+ ReinstallBlockIoFlag = FALSE;
+ break;
+
+ case ERROR_WRONG_DISK:
+ BlockIo->Media->ReadOnly = FALSE;
+ BlockIo->Media->MediaPresent = TRUE;
+ BlockIo->Media->MediaId += 1;
+ ReinstallBlockIoFlag = TRUE;
+ Status = EFI_MEDIA_CHANGED;
+ break;
+
+ case ERROR_WRITE_PROTECT:
+ BlockIo->Media->ReadOnly = TRUE;
+ ReinstallBlockIoFlag = FALSE;
+ Status = EFI_WRITE_PROTECTED;
+ break;
+
+ default:
+ ReinstallBlockIoFlag = FALSE;
+ Status = EFI_DEVICE_ERROR;
+ break;
+ }
+
+ if (ReinstallBlockIoFlag) {
+ BlockIo->Reset (BlockIo, FALSE);
+
+ gBS->ReinstallProtocolInterface (
+ Private->EfiHandle,
+ &gEfiBlockIoProtocolGuid,
+ BlockIo,
+ BlockIo
+ );
+ }
+
+ return Status;
+#endif
+}
+
+STATIC
+EFI_STATUS
+UnixBlockIoReadWriteCommon (
+ IN UNIX_BLOCK_IO_PRIVATE *Private,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ IN VOID *Buffer,
+ IN CHAR8 *CallerName
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+ MediaId - TODO: add argument description
+ Lba - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+ CallerName - TODO: add argument description
+
+Returns:
+
+ EFI_NO_MEDIA - TODO: Add description for return value
+ EFI_MEDIA_CHANGED - TODO: Add description for return value
+ EFI_INVALID_PARAMETER - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+ EFI_BAD_BUFFER_SIZE - TODO: Add description for return value
+ EFI_INVALID_PARAMETER - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN BlockSize;
+ UINT64 LastBlock;
+ INT64 DistanceToMove;
+ UINT64 DistanceMoved;
+
+ if (Private->fd < 0) {
+ Status = UnixBlockIoOpenDevice (Private);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ if (!Private->Media.MediaPresent) {
+ DEBUG ((EFI_D_INIT, "%s: No Media\n", CallerName));
+ return EFI_NO_MEDIA;
+ }
+
+ if (Private->Media.MediaId != MediaId) {
+ return EFI_MEDIA_CHANGED;
+ }
+
+ if ((UINT32) Buffer % Private->Media.IoAlign != 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Verify buffer size
+ //
+ BlockSize = Private->BlockSize;
+ if (BufferSize == 0) {
+ DEBUG ((EFI_D_INIT, "%s: Zero length read\n", CallerName));
+ return EFI_SUCCESS;
+ }
+
+ if ((BufferSize % BlockSize) != 0) {
+ DEBUG ((EFI_D_INIT, "%s: Invalid read size\n", CallerName));
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ LastBlock = Lba + (BufferSize / BlockSize) - 1;
+ if (LastBlock > Private->LastBlock) {
+ DEBUG ((EFI_D_INIT, "ReadBlocks: Attempted to read off end of device\n"));
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Seek to End of File
+ //
+ DistanceToMove = MultU64x32 (Lba, BlockSize);
+ Status = SetFilePointer64 (Private, DistanceToMove, &DistanceMoved, SEEK_SET);
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_INIT, "WriteBlocks: SetFilePointer failed\n"));
+ return UnixBlockIoError (Private);
+ }
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoReadBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+ Routine Description:
+ Read BufferSize bytes from Lba into Buffer.
+
+ Arguments:
+ This - Protocol instance pointer.
+ MediaId - Id of the media, changes every time the media is replaced.
+ Lba - The starting Logical Block Address to read from
+ BufferSize - Size of Buffer, must be a multiple of device block size.
+ Buffer - Buffer containing read data
+
+ Returns:
+ EFI_SUCCESS - The data was read correctly from the device.
+ EFI_DEVICE_ERROR - The device reported an error while performing the read.
+ EFI_NO_MEDIA - There is no media in the device.
+ EFI_MEDIA_CHANGED - The MediaId does not matched the current device.
+ EFI_BAD_BUFFER_SIZE - The Buffer was not a multiple of the block size of the
+ device.
+ EFI_INVALID_PARAMETER - The read request contains device addresses that are not
+ valid for the device.
+
+--*/
+{
+ UNIX_BLOCK_IO_PRIVATE *Private;
+ ssize_t len;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ Status = UnixBlockIoReadWriteCommon (Private, MediaId, Lba, BufferSize, Buffer, "UnixReadBlocks");
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ len = Private->UnixThunk->Read (Private->fd, Buffer, BufferSize);
+ if (len != BufferSize) {
+ DEBUG ((EFI_D_INIT, "ReadBlocks: ReadFile failed.\n"));
+ Status = UnixBlockIoError (Private);
+ goto Done;
+ }
+
+ //
+ // If we wrote then media is present.
+ //
+ This->Media->MediaPresent = TRUE;
+ Status = EFI_SUCCESS;
+
+Done:
+ gBS->RestoreTPL (OldTpl);
+ return Status;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoWriteBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ )
+/*++
+
+ Routine Description:
+ Write BufferSize bytes from Lba into Buffer.
+
+ Arguments:
+ This - Protocol instance pointer.
+ MediaId - Id of the media, changes every time the media is replaced.
+ Lba - The starting Logical Block Address to read from
+ BufferSize - Size of Buffer, must be a multiple of device block size.
+ Buffer - Buffer containing read data
+
+ Returns:
+ EFI_SUCCESS - The data was written correctly to the device.
+ EFI_WRITE_PROTECTED - The device can not be written to.
+ EFI_DEVICE_ERROR - The device reported an error while performing the write.
+ EFI_NO_MEDIA - There is no media in the device.
+ EFI_MEDIA_CHNAGED - The MediaId does not matched the current device.
+ EFI_BAD_BUFFER_SIZE - The Buffer was not a multiple of the block size of the
+ device.
+ EFI_INVALID_PARAMETER - The write request contains a LBA that is not
+ valid for the device.
+
+--*/
+{
+ UNIX_BLOCK_IO_PRIVATE *Private;
+ ssize_t len;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ Status = UnixBlockIoReadWriteCommon (Private, MediaId, Lba, BufferSize, Buffer, "UnixWriteBlocks");
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ len = Private->UnixThunk->Write (Private->fd, Buffer, BufferSize);
+ if (len != BufferSize) {
+ DEBUG ((EFI_D_INIT, "ReadBlocks: WriteFile failed.\n"));
+ Status = UnixBlockIoError (Private);
+ goto Done;
+ }
+
+ //
+ // If the write succeeded, we are not write protected and media is present.
+ //
+ This->Media->MediaPresent = TRUE;
+ This->Media->ReadOnly = FALSE;
+ Status = EFI_SUCCESS;
+
+Done:
+ gBS->RestoreTPL (OldTpl);
+ return Status;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoFlushBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This
+ )
+/*++
+
+ Routine Description:
+ Flush the Block Device.
+
+ Arguments:
+ This - Protocol instance pointer.
+
+ Returns:
+ EFI_SUCCESS - All outstanding data was written to the device
+ EFI_DEVICE_ERROR - The device reported an error while writting back the data
+ EFI_NO_MEDIA - There is no media in the device.
+
+--*/
+{
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoResetBlock (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
+ )
+/*++
+
+ Routine Description:
+ Reset the Block Device.
+
+ Arguments:
+ This - Protocol instance pointer.
+ ExtendedVerification - Driver may perform diagnostics on reset.
+
+ Returns:
+ EFI_SUCCESS - The device was reset.
+ EFI_DEVICE_ERROR - The device is not functioning properly and could
+ not be reset.
+
+--*/
+{
+ UNIX_BLOCK_IO_PRIVATE *Private;
+ EFI_TPL OldTpl;
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ if (Private->fd >= 0) {
+ Private->UnixThunk->Close (Private->fd);
+ Private->fd = -1;
+ }
+
+ gBS->RestoreTPL (OldTpl);
+
+ return EFI_SUCCESS;
+}
+
+UINTN
+Atoi (
+ CHAR16 *String
+ )
+/*++
+
+Routine Description:
+
+ Convert a unicode string to a UINTN
+
+Arguments:
+
+ String - Unicode string.
+
+Returns:
+
+ UINTN of the number represented by String.
+
+--*/
+{
+ UINTN Number;
+ CHAR16 *Str;
+
+ //
+ // skip preceeding white space
+ //
+ Str = String;
+ while ((*Str) && (*Str == ' ')) {
+ Str++;
+ }
+ //
+ // Convert ot a Number
+ //
+ Number = 0;
+ while (*Str != '\0') {
+ if ((*Str >= '0') && (*Str <= '9')) {
+ Number = (Number * 10) +*Str - '0';
+ } else {
+ break;
+ }
+
+ Str++;
+ }
+
+ return Number;
+}
+
+EFI_STATUS
+SetFilePointer64 (
+ IN UNIX_BLOCK_IO_PRIVATE *Private,
+ IN INT64 DistanceToMove,
+ OUT UINT64 *NewFilePointer,
+ IN INTN MoveMethod
+ )
+/*++
+
+This function extends the capability of SetFilePointer to accept 64 bit parameters
+
+--*/
+// TODO: function comment is missing 'Routine Description:'
+// TODO: function comment is missing 'Arguments:'
+// TODO: function comment is missing 'Returns:'
+// TODO: Private - add argument and description to function comment
+// TODO: DistanceToMove - add argument and description to function comment
+// TODO: NewFilePointer - add argument and description to function comment
+// TODO: MoveMethod - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ off_t res;
+
+ res = Private->UnixThunk->Lseek(Private->fd, DistanceToMove, MoveMethod);
+ if (res == -1) {
+ Status = EFI_INVALID_PARAMETER;
+ }
+
+ if (NewFilePointer != NULL) {
+ *NewFilePointer = res;
+ }
+
+ return Status;
+}
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h
new file mode 100644
index 0000000000..c446f31d95
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h
@@ -0,0 +1,219 @@
+/*++
+
+Copyright (c) 2004 - 2008, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+ UnixBlockIo.h
+
+Abstract:
+
+ Produce block IO abstractions for real devices on your PC using Posix APIs.
+ The configuration of what devices to mount or emulate comes from UNIX
+ environment variables. The variables must be visible to the Microsoft*
+ Developer Studio for them to work.
+
+ * Other names and brands may be claimed as the property of others.
+
+--*/
+
+#ifndef _UNIX_BLOCK_IO_H_
+#define _UNIX_BLOCK_IO_H_
+
+#include "PiDxe.h"
+#include <Protocol/BlockIo.h>
+
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include "UnixDxe.h"
+
+#define FILENAME_BUFFER_SIZE 80
+
+//
+// Language supported for driverconfiguration protocol
+//
+#define LANGUAGESUPPORTED "eng"
+
+#define UNIX_BLOCK_IO_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('L', 'X', 'b', 'k')
+typedef struct {
+ UINTN Signature;
+
+ EFI_LOCK Lock;
+
+ char Filename[FILENAME_BUFFER_SIZE];
+ UINTN ReadMode;
+ UINTN Mode;
+
+ int fd;
+
+ UINT64 LastBlock;
+ UINTN BlockSize;
+ UINT64 NumberOfBlocks;
+
+ EFI_HANDLE EfiHandle;
+ EFI_BLOCK_IO_PROTOCOL BlockIo;
+ EFI_BLOCK_IO_MEDIA Media;
+
+ EFI_UNICODE_STRING_TABLE *ControllerNameTable;
+
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
+
+} UNIX_BLOCK_IO_PRIVATE;
+
+#define UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS(a) \
+ CR(a, UNIX_BLOCK_IO_PRIVATE, BlockIo, UNIX_BLOCK_IO_PRIVATE_SIGNATURE)
+
+#define LIST_BUFFER_SIZE 512
+
+//
+// Block I/O Global Variables
+//
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixBlockIoDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixBlockIoComponentName;
+extern EFI_DRIVER_CONFIGURATION_PROTOCOL gUnixBlockIoDriverConfiguration;
+extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL gUnixBlockIoDriverDiagnostics;
+
+//
+// EFI Driver Binding Functions
+//
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Handle - TODO: add argument description
+ RemainingDevicePath - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Handle - TODO: add argument description
+ RemainingDevicePath - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Handle - TODO: add argument description
+ NumberOfChildren - TODO: add argument description
+ ChildHandleBuffer - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+SetFilePointer64 (
+ IN UNIX_BLOCK_IO_PRIVATE *Private,
+ IN INT64 DistanceToMove,
+ OUT UINT64 *NewFilePointer,
+ IN INT32 MoveMethod
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+ DistanceToMove - TODO: add argument description
+ NewFilePointer - TODO: add argument description
+ MoveMethod - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+UINTN
+Atoi (
+ CHAR16 *String
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ String - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+#endif
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf
new file mode 100644
index 0000000000..00371add9d
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf
@@ -0,0 +1,71 @@
+#/** @file
+# Block Io driver
+#
+# Produce block IO abstractions for real devices on your PC using Unix APIs.
+# The configuration of what devices to mount or emulate comes from
+# environment variables.
+# Copyright (c) 2006, Intel Corporation
+#
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixBlockIo
+ FILE_GUID = f3085888-8985-11db-9c93-0040d02b1835
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeUnixBlockIo
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+# DRIVER_BINDING = gUnixBlockIoDriverBinding
+# COMPONENT_NAME = gUnixBlockIoComponentName
+# DRIVER_DIAG = gUnixBlockIoDriverDiagnostics
+#
+
+[Sources.common]
+ DriverDiagnostics.c
+ DriverConfiguration.c
+ ComponentName.c
+ UnixBlockIo.c
+ UnixBlockIo.h
+ EntryPoint.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ BaseMemoryLib
+ UefiLib
+ UefiDriverEntryPoint
+ BaseLib
+ DebugLib
+
+
+[Guids]
+ gEfiUnixPhysicalDisksGuid # SOMETIMES_CONSUMED
+ gEfiUnixVirtualDisksGuid # ALWAYS_CONSUMED
+
+
+[Protocols]
+ gEfiBlockIoProtocolGuid # PROTOCOL BY_START
+ gEfiUnixIoProtocolGuid # PROTOCOL TO_START
+
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa
new file mode 100644
index 0000000000..49334904b0
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>UnixBlockIo</ModuleName>
+ <ModuleType>UEFI_DRIVER</ModuleType>
+ <GuidValue>f3085888-8985-11db-9c93-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Block Io driver</Abstract>
+ <Description>
+ Produce block IO abstractions for real devices on your PC using Unix APIs.
+ The configuration of what devices to mount or emulate comes from
+ environment variables.
+ </Description>
+ <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>
+ <License>All rights reserved. This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
+ </MsaHeader>
+ <ModuleDefinitions>
+ <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
+ <BinaryModule>false</BinaryModule>
+ <OutputFileBasename>UnixBlockIo</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverModelLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverEntryPoint</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixBlockIo.h</Filename>
+ <Filename>UnixBlockIo.c</Filename>
+ <Filename>ComponentName.c</Filename>
+ <Filename>DriverConfiguration.c</Filename>
+ <Filename>DriverDiagnostics.c</Filename>
+ </SourceFiles>
+ <PackageDependencies>
+ <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
+ <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
+ <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>
+ </PackageDependencies>
+ <Protocols>
+ <Protocol Usage="TO_START">
+ <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="BY_START">
+ <ProtocolCName>gEfiBlockIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixVirtualDisksGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiUnixPhysicalDisksGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <DriverBinding>gUnixBlockIoDriverBinding</DriverBinding>
+ <ComponentName>gUnixBlockIoComponentName</ComponentName>
+ <DriverDiag>gUnixBlockIoDriverDiagnostics</DriverDiag>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>