]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add WinNtSerialIoDxe driver into Nt32Pkg
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 27 Jun 2007 07:00:49 +0000 (07:00 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 27 Jun 2007 07:00:49 +0000 (07:00 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2785 6f19259b-4bc3-4df7-8a09-765794883524

Nt32Pkg/Nt32.dsc
Nt32Pkg/WinNtGopDxe/WinNtGop.h
Nt32Pkg/WinNtSerialIoDxe/ComponentName.c [new file with mode: 0644]
Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.c [new file with mode: 0644]
Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.h [new file with mode: 0644]
Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.inf [new file with mode: 0644]
Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.msa [new file with mode: 0644]

index 28e046fcd20cc57c64a8b7d2129eb2d071d4de7f..9a43453ee4acabdca217bbe5c3df5163c4246fdb 100644 (file)
   $(WORKSPACE)\Nt32Pkg\WinNtConsoleDxe\WinNtConsole.inf\r
   $(WORKSPACE)\Nt32Pkg\WinNtSimpleFileSystemDxe\WinNtSimpleFileSystem.inf\r
   $(WORKSPACE)\Nt32Pkg\WinNtGopDxe\WinNtGop.inf\r
+  $(WORKSPACE)\Nt32Pkg\WinNtSerialIoDxe\WinNtSerialIo.inf\r
index cc7283ebf688c41fead3a1e7d3878a06603091ee..74cfe41e15c3ccc0f667821471f76d73467a8b55 100644 (file)
@@ -23,11 +23,6 @@ Abstract:
 #ifndef _WIN_NT_GOP_H_\r
 #define _WIN_NT_GOP_H_\r
 \r
-//\r
-// Include common header file for this module.\r
-//\r
-#include "CommonHeader.h"\r
-\r
 //@MT:#include "EfiWinNT.h"\r
 //@MT:#include "Tiano.h"\r
 //@MT:#include "EfiDriverLib.h"\r
diff --git a/Nt32Pkg/WinNtSerialIoDxe/ComponentName.c b/Nt32Pkg/WinNtSerialIoDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..5454291
--- /dev/null
@@ -0,0 +1,232 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+#include <WinNtDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/WinNtIo.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/SerialIo.h>\r
+#include <Protocol/DriverBinding.h>\r
+#include <Protocol/DevicePath.h>\r
+//\r
+// The Library classes this module consumes\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/UefiBootServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include "WinNtSerialIo.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoComponentNameGetControllerName (\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
+EFI_COMPONENT_NAME_PROTOCOL     gWinNtSerialIoComponentName = {\r
+  WinNtSerialIoComponentNameGetDriverName,\r
+  WinNtSerialIoComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mWinNtSerialIoDriverNameTable[] = {\r
+  { "eng", L"Windows Serial I/O Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller \r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a \r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language \r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gWinNtSerialIoComponentName.SupportedLanguages,\r
+          mWinNtSerialIoDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoComponentNameGetControllerName (\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
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language specified\r
+                       by Language from the point of view of the driver specified\r
+                       by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the \r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\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 - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently managing \r
+                            the controller specified by ControllerHandle and \r
+                            ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_SERIAL_IO_PROTOCOL        *SerialIo;\r
+  WIN_NT_SERIAL_IO_PRIVATE_DATA *Private;\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gWinNtSerialIoDriverBinding.DriverBindingHandle,\r
+             &gEfiWinNtIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // This is a bus driver, so ChildHandle must not be NULL.\r
+  //\r
+  if (ChildHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = EfiTestChildHandle (\r
+             ControllerHandle,\r
+             ChildHandle,\r
+             &gEfiWinNtIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ChildHandle,\r
+                  &gEfiSerialIoProtocolGuid,\r
+                  &SerialIo,\r
+                  gWinNtSerialIoDriverBinding.DriverBindingHandle,\r
+                  ChildHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (SerialIo);\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gWinNtSerialIoComponentName.SupportedLanguages,\r
+          Private->ControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
diff --git a/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.c b/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.c
new file mode 100644 (file)
index 0000000..8500140
--- /dev/null
@@ -0,0 +1,1468 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  WinNtSerialIo.c\r
+\r
+Abstract:\r
+\r
+  Our DriverBinding member functions operate on the handles\r
+  created by the NT Bus driver.\r
+\r
+  Handle(1) - WinNtIo - DevicePath(1)\r
+\r
+  If a serial port is added to the system this driver creates a new handle.\r
+  The new handle is required, since the serial device must add an UART device\r
+  pathnode.\r
+\r
+  Handle(2) - SerialIo - DevicePath(1)\UART\r
+\r
+  The driver then adds a gEfiWinNtSerialPortGuid as a protocol to Handle(1).\r
+  The instance data for this protocol is the private data used to create\r
+  Handle(2).\r
+\r
+  Handle(1) - WinNtIo - DevicePath(1) - WinNtSerialPort\r
+\r
+  If the driver is unloaded Handle(2) is removed from the system and\r
+  gEfiWinNtSerialPortGuid is removed from Handle(1).\r
+\r
+  Note: Handle(1) is any handle created by the Win NT Bus driver that is passed\r
+  into the DriverBinding member functions of this driver. This driver requires\r
+  a Handle(1) to contain a WinNtIo protocol, a DevicePath protocol, and\r
+  the TypeGuid in the WinNtIo must be gEfiWinNtSerialPortGuid.\r
+\r
+  If Handle(1) contains a gEfiWinNtSerialPortGuid protocol then the driver is\r
+  loaded on the device.\r
+\r
+--*/\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+#include <WinNtDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/WinNtIo.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/SerialIo.h>\r
+#include <Protocol/DriverBinding.h>\r
+#include <Protocol/DevicePath.h>\r
+//\r
+// The Library classes this module consumes\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/UefiBootServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include "WinNtSerialIo.h"\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gWinNtSerialIoDriverBinding = {\r
+  WinNtSerialIoDriverBindingSupported,\r
+  WinNtSerialIoDriverBindingStart,\r
+  WinNtSerialIoDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+/**\r
+  The user Entry Point for module WinNtSerialIo. 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
+InitializeWinNtSerialIo(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gWinNtSerialIoDriverBinding,\r
+             ImageHandle,\r
+             &gWinNtSerialIoComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoDriverBindingSupported (\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
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EFI_WIN_NT_IO_PROTOCOL    *WinNtIo;\r
+  UART_DEVICE_PATH          *UartNode;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  &ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEfiDevicePathProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiWinNtIoProtocolGuid,\r
+                  &WinNtIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Make sure that the WinNt Thunk Protocol is valid\r
+  //\r
+  if (WinNtIo->WinNtThunk->Signature != EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // Check the GUID to see if this is a handle type the driver supports\r
+  //\r
+  if (!CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtSerialPortGuid)) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Error;\r
+  }\r
+\r
+  if (RemainingDevicePath != NULL) {\r
+    Status    = EFI_UNSUPPORTED;\r
+    UartNode  = (UART_DEVICE_PATH *) RemainingDevicePath;\r
+    if (UartNode->Header.Type != MESSAGING_DEVICE_PATH ||\r
+        UartNode->Header.SubType != MSG_UART_DP ||\r
+        DevicePathNodeLength((EFI_DEVICE_PATH_PROTOCOL *)UartNode) != sizeof(UART_DEVICE_PATH)) {\r
+      goto Error;\r
+    }\r
+    if (UartNode->BaudRate < 0 || UartNode->BaudRate > SERIAL_PORT_MAX_BAUD_RATE) {\r
+      goto Error;\r
+    }\r
+    if (UartNode->Parity < NoParity || UartNode->Parity > SpaceParity) {\r
+      goto Error;\r
+    }\r
+    if (UartNode->DataBits < 5 || UartNode->DataBits > 8) {\r
+      goto Error;\r
+    }\r
+    if (UartNode->StopBits < OneStopBit || UartNode->StopBits > TwoStopBits) {\r
+      goto Error;\r
+    }\r
+    if ((UartNode->DataBits == 5) && (UartNode->StopBits == TwoStopBits)) {\r
+      goto Error;\r
+    }\r
+    if ((UartNode->DataBits >= 6) && (UartNode->DataBits <= 8) && (UartNode->StopBits == OneFiveStopBits)) {\r
+      goto Error;\r
+    }\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+Error:\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEfiWinNtIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoDriverBindingStart (\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
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_WIN_NT_IO_PROTOCOL              *WinNtIo;\r
+  WIN_NT_SERIAL_IO_PRIVATE_DATA       *Private;\r
+  HANDLE                              NtHandle;\r
+  UART_DEVICE_PATH                    Node;\r
+  EFI_DEVICE_PATH_PROTOCOL            *ParentDevicePath;\r
+  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
+  UINTN                               EntryCount;\r
+  UINTN                               Index;\r
+  EFI_SERIAL_IO_PROTOCOL              *SerialIo;\r
+\r
+  Private   = NULL;\r
+  NtHandle  = INVALID_HANDLE_VALUE;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  &ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Grab the IO abstraction we need to get any work done\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiWinNtIoProtocolGuid,\r
+                  &WinNtIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEfiDevicePathProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+    return Status;\r
+  }\r
+\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+\r
+    if (RemainingDevicePath == NULL) {\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    //\r
+    // Make sure a child handle does not already exist.  This driver can only\r
+    // produce one child per serial port.\r
+    //\r
+    Status = gBS->OpenProtocolInformation (\r
+                    Handle,\r
+                    &gEfiWinNtIoProtocolGuid,\r
+                    &OpenInfoBuffer,\r
+                    &EntryCount\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = EFI_ALREADY_STARTED;\r
+    for (Index = 0; Index < EntryCount; Index++) {\r
+      if (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {\r
+        Status = gBS->OpenProtocol (\r
+                        OpenInfoBuffer[Index].ControllerHandle,\r
+                        &gEfiSerialIoProtocolGuid,\r
+                        &SerialIo,\r
+                        This->DriverBindingHandle,\r
+                        Handle,\r
+                        EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                        );\r
+        if (!EFI_ERROR (Status)) {\r
+          CopyMem (&Node, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\r
+          Status = SerialIo->SetAttributes (\r
+                              SerialIo,\r
+                              Node.BaudRate,\r
+                              SerialIo->Mode->ReceiveFifoDepth,\r
+                              SerialIo->Mode->Timeout,\r
+                              Node.Parity,\r
+                              Node.DataBits,\r
+                              Node.StopBits\r
+                              );\r
+        }\r
+        break;\r
+      }\r
+    }\r
+\r
+    FreePool (OpenInfoBuffer);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Check to see if we can access the hardware device. If it's Open in NT we\r
+  // will not get access.\r
+  //\r
+  NtHandle = WinNtIo->WinNtThunk->CreateFile (\r
+                                    WinNtIo->EnvString,\r
+                                    GENERIC_READ | GENERIC_WRITE,\r
+                                    0,\r
+                                    NULL,\r
+                                    OPEN_EXISTING,\r
+                                    0,\r
+                                    NULL\r
+                                    );\r
+  if (NtHandle == INVALID_HANDLE_VALUE) {\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // Construct Private data\r
+  //\r
+  Private = AllocatePool (sizeof (WIN_NT_SERIAL_IO_PRIVATE_DATA));\r
+  if (Private == NULL) {\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // This signature must be valid before any member function is called\r
+  //\r
+  Private->Signature              = WIN_NT_SERIAL_IO_PRIVATE_DATA_SIGNATURE;\r
+  Private->NtHandle               = NtHandle;\r
+  Private->ControllerHandle       = Handle;\r
+  Private->Handle                 = NULL;\r
+  Private->WinNtThunk             = WinNtIo->WinNtThunk;\r
+  Private->ParentDevicePath       = ParentDevicePath;\r
+  Private->ControllerNameTable    = NULL;\r
+\r
+  Private->SoftwareLoopbackEnable = FALSE;\r
+  Private->HardwareLoopbackEnable = FALSE;\r
+  Private->HardwareFlowControl    = FALSE;\r
+  Private->Fifo.First             = 0;\r
+  Private->Fifo.Last              = 0;\r
+  Private->Fifo.Surplus           = SERIAL_MAX_BUFFER_SIZE;\r
+\r
+  AddUnicodeString (\r
+    "eng",\r
+    gWinNtSerialIoComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    WinNtIo->EnvString\r
+    );\r
+\r
+  Private->SerialIo.Revision      = SERIAL_IO_INTERFACE_REVISION;\r
+  Private->SerialIo.Reset         = WinNtSerialIoReset;\r
+  Private->SerialIo.SetAttributes = WinNtSerialIoSetAttributes;\r
+  Private->SerialIo.SetControl    = WinNtSerialIoSetControl;\r
+  Private->SerialIo.GetControl    = WinNtSerialIoGetControl;\r
+  Private->SerialIo.Write         = WinNtSerialIoWrite;\r
+  Private->SerialIo.Read          = WinNtSerialIoRead;\r
+  Private->SerialIo.Mode          = &Private->SerialIoMode;\r
+\r
+  if (RemainingDevicePath != NULL) {\r
+    //\r
+    // Match the configuration of the RemainingDevicePath. IsHandleSupported()\r
+    // already checked to make sure the RemainingDevicePath contains settings\r
+    // that we can support.\r
+    //\r
+    CopyMem (&Private->UartDevicePath, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\r
+  } else {\r
+    //\r
+    // Build the device path by appending the UART node to the ParentDevicePath\r
+    // from the WinNtIo handle. The Uart setings are zero here, since\r
+    // SetAttribute() will update them to match the default setings.\r
+    //\r
+    ZeroMem (&Private->UartDevicePath, sizeof (UART_DEVICE_PATH));\r
+    Private->UartDevicePath.Header.Type     = MESSAGING_DEVICE_PATH;\r
+    Private->UartDevicePath.Header.SubType  = MSG_UART_DP;\r
+    SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath, sizeof (UART_DEVICE_PATH));\r
+  }\r
+\r
+  //\r
+  // Build the device path by appending the UART node to the ParentDevicePath\r
+  // from the WinNtIo handle. The Uart setings are zero here, since\r
+  // SetAttribute() will update them to match the current setings.\r
+  //\r
+  Private->DevicePath = AppendDevicePathNode (\r
+                          ParentDevicePath,\r
+                          (EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath\r
+                          );\r
+  if (Private->DevicePath == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // Fill in Serial I/O Mode structure based on either the RemainingDevicePath or defaults.\r
+  //\r
+  Private->SerialIoMode.ControlMask       = SERIAL_CONTROL_MASK;\r
+  Private->SerialIoMode.Timeout           = SERIAL_TIMEOUT_DEFAULT;\r
+  Private->SerialIoMode.BaudRate          = Private->UartDevicePath.BaudRate;\r
+  Private->SerialIoMode.ReceiveFifoDepth  = SERIAL_FIFO_DEFAULT;\r
+  Private->SerialIoMode.DataBits          = Private->UartDevicePath.DataBits;\r
+  Private->SerialIoMode.Parity            = Private->UartDevicePath.Parity;\r
+  Private->SerialIoMode.StopBits          = Private->UartDevicePath.StopBits;\r
+\r
+  //\r
+  // Issue a reset to initialize the COM port\r
+  //\r
+  Status = Private->SerialIo.Reset (&Private->SerialIo);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // Create new child handle\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Private->Handle,\r
+                  &gEfiSerialIoProtocolGuid,\r
+                  &Private->SerialIo,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  Private->DevicePath,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // Open For Child Device\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiWinNtIoProtocolGuid,\r
+                  &WinNtIo,\r
+                  This->DriverBindingHandle,\r
+                  Private->Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+\r
+Error:\r
+  //\r
+  // Use the Stop() function to free all resources allocated in Start()\r
+  //\r
+  if (Private != NULL) {\r
+    if (Private->Handle != NULL) {\r
+      This->Stop (This, Handle, 1, &Private->Handle);\r
+    } else {\r
+      if (NtHandle != INVALID_HANDLE_VALUE) {\r
+        Private->WinNtThunk->CloseHandle (NtHandle);\r
+      }\r
+\r
+      if (Private->DevicePath != NULL) {\r
+        FreePool (Private->DevicePath);\r
+      }\r
+\r
+      FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+      FreePool (Private);\r
+    }\r
+  }\r
+\r
+  This->Stop (This, Handle, 0, NULL);\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  UINTN                         NumberOfChildren,\r
+  IN  EFI_HANDLE                    *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  Handle            - TODO: add argument description\r
+  NumberOfChildren  - TODO: add argument description\r
+  ChildHandleBuffer - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                    Status;\r
+  UINTN                         Index;\r
+  BOOLEAN                       AllChildrenStopped;\r
+  EFI_SERIAL_IO_PROTOCOL        *SerialIo;\r
+  WIN_NT_SERIAL_IO_PRIVATE_DATA *Private;\r
+  EFI_WIN_NT_IO_PROTOCOL        *WinNtIo;\r
+\r
+  //\r
+  // Complete all outstanding transactions to Controller.\r
+  // Don't allow any new transaction to Controller to be started.\r
+  //\r
+\r
+  if (NumberOfChildren == 0) {\r
+    //\r
+    // Close the bus driver\r
+    //\r
+    Status = gBS->CloseProtocol (\r
+                    Handle,\r
+                    &gEfiWinNtIoProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    Handle\r
+                    );\r
+    Status = gBS->CloseProtocol (\r
+                    Handle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    Handle\r
+                    );\r
+    return Status;\r
+  }\r
+\r
+  AllChildrenStopped = TRUE;\r
+\r
+  for (Index = 0; Index < NumberOfChildren; Index++) {\r
+    Status = gBS->OpenProtocol (\r
+                    ChildHandleBuffer[Index],\r
+                    &gEfiSerialIoProtocolGuid,\r
+                    &SerialIo,\r
+                    This->DriverBindingHandle,\r
+                    Handle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      Private = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (SerialIo);\r
+\r
+      ASSERT (Private->Handle == ChildHandleBuffer[Index]);\r
+\r
+      Status = gBS->CloseProtocol (\r
+                      Handle,\r
+                      &gEfiWinNtIoProtocolGuid,\r
+                      This->DriverBindingHandle,\r
+                      ChildHandleBuffer[Index]\r
+                      );\r
+\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      ChildHandleBuffer[Index],\r
+                      &gEfiSerialIoProtocolGuid,\r
+                      &Private->SerialIo,\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      Private->DevicePath,\r
+                      NULL\r
+                      );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        gBS->OpenProtocol (\r
+              Handle,\r
+              &gEfiWinNtIoProtocolGuid,\r
+              (VOID **) &WinNtIo,\r
+              This->DriverBindingHandle,\r
+              ChildHandleBuffer[Index],\r
+              EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+              );\r
+      } else {\r
+        Private->WinNtThunk->CloseHandle (Private->NtHandle);\r
+\r
+        FreePool (Private->DevicePath);\r
+\r
+        FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+        FreePool (Private);\r
+      }\r
+    }\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      AllChildrenStopped = FALSE;\r
+    }\r
+  }\r
+\r
+  if (!AllChildrenStopped) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+//\r
+// Serial IO Protocol member functions\r
+//\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoReset (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  WIN_NT_SERIAL_IO_PRIVATE_DATA *Private;\r
+  EFI_TPL                       Tpl;\r
+\r
+  Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Private->WinNtThunk->PurgeComm (\r
+                        Private->NtHandle,\r
+                        PURGE_TXCLEAR | PURGE_RXCLEAR\r
+                        );\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return This->SetAttributes (\r
+                This,\r
+                This->Mode->BaudRate,\r
+                This->Mode->ReceiveFifoDepth,\r
+                This->Mode->Timeout,\r
+                This->Mode->Parity,\r
+                (UINT8) This->Mode->DataBits,\r
+                This->Mode->StopBits\r
+                );\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoSetAttributes (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This,\r
+  IN UINT64                 BaudRate,\r
+  IN UINT32                 ReceiveFifoDepth,\r
+  IN UINT32                 Timeout,\r
+  IN EFI_PARITY_TYPE        Parity,\r
+  IN UINT8                  DataBits,\r
+  IN EFI_STOP_BITS_TYPE     StopBits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function is used to set the attributes.\r
+\r
+Arguments:\r
+\r
+  This              - A pointer to the EFI_SERIAL_IO_PROTOCOL structrue.\r
+  BaudRate          - The Baud rate of the serial device.\r
+  ReceiveFifoDepth  - The request depth of fifo on receive side.\r
+  Timeout           - the request timeout for a single charact.\r
+  Parity            - The type of parity used in serial device.\r
+  DataBits          - Number of deata bits used in serial device.\r
+  StopBits          - Number of stop bits used in serial device.\r
+\r
+Returns:\r
+  Status code\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+// TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+// TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+// TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+// TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS                    Status;\r
+  WIN_NT_SERIAL_IO_PRIVATE_DATA *Private;\r
+  COMMTIMEOUTS                  PortTimeOuts;\r
+  DWORD                         ConvertedTime;\r
+  BOOL                          Result;\r
+  EFI_DEVICE_PATH_PROTOCOL      *NewDevicePath;\r
+  EFI_TPL                       Tpl;\r
+\r
+  Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  //  Some of our arguments have defaults if a null value is passed in, and\r
+  //   we must set the default values if a null argument is passed in.\r
+  //\r
+  if (BaudRate == 0) {\r
+    BaudRate = SERIAL_BAUD_DEFAULT;\r
+  }\r
+\r
+  if (ReceiveFifoDepth == 0) {\r
+    ReceiveFifoDepth = SERIAL_FIFO_DEFAULT;\r
+  }\r
+\r
+  if (Timeout == 0) {\r
+    Timeout = SERIAL_TIMEOUT_DEFAULT;\r
+  }\r
+\r
+  if (Parity == DefaultParity) {\r
+    Parity = NoParity;\r
+  }\r
+\r
+  if (DataBits == 0) {\r
+    DataBits = SERIAL_DATABITS_DEFAULT;\r
+  }\r
+\r
+  if (StopBits == DefaultStopBits) {\r
+    StopBits = OneStopBit;\r
+  }\r
+  //\r
+  // See if the new attributes already match the current attributes\r
+  //\r
+  if (Private->UartDevicePath.BaudRate       == BaudRate         &&\r
+      Private->UartDevicePath.DataBits       == DataBits         &&\r
+      Private->UartDevicePath.Parity         == Parity           &&\r
+      Private->UartDevicePath.StopBits       == StopBits         &&\r
+      Private->SerialIoMode.ReceiveFifoDepth == ReceiveFifoDepth &&\r
+      Private->SerialIoMode.Timeout          == Timeout             ) {\r
+    gBS->RestoreTPL(Tpl);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  //  Get current values from NT\r
+  //\r
+  ZeroMem (&Private->NtDCB, sizeof (DCB));\r
+  Private->NtDCB.DCBlength = sizeof (DCB);\r
+\r
+  if (!Private->WinNtThunk->GetCommState (Private->NtHandle, &Private->NtDCB)) {\r
+    Private->NtError = Private->WinNtThunk->GetLastError ();\r
+    DEBUG ((EFI_D_ERROR, "SerialSetAttributes: GetCommState %d\n", Private->NtError));\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // Map EFI com setting to NT\r
+  //\r
+  Private->NtDCB.BaudRate         = ConvertBaud2Nt (BaudRate);\r
+  Private->NtDCB.ByteSize         = ConvertData2Nt (DataBits);\r
+  Private->NtDCB.Parity           = ConvertParity2Nt (Parity);\r
+  Private->NtDCB.StopBits         = ConvertStop2Nt (StopBits);\r
+\r
+  Private->NtDCB.fBinary          = TRUE;\r
+  Private->NtDCB.fParity          = Private->NtDCB.Parity == NOPARITY ? FALSE : TRUE;\r
+  Private->NtDCB.fOutxCtsFlow     = FALSE;\r
+  Private->NtDCB.fOutxDsrFlow     = FALSE;\r
+  Private->NtDCB.fDtrControl      = DTR_CONTROL_ENABLE;\r
+  Private->NtDCB.fDsrSensitivity  = FALSE;\r
+  Private->NtDCB.fOutX            = FALSE;\r
+  Private->NtDCB.fInX             = FALSE;\r
+  Private->NtDCB.fRtsControl      = RTS_CONTROL_ENABLE;\r
+  Private->NtDCB.fNull            = FALSE;\r
+\r
+  //\r
+  //  Set new values\r
+  //\r
+  Result = Private->WinNtThunk->SetCommState (Private->NtHandle, &Private->NtDCB);\r
+  if (!Result) {\r
+    Private->NtError = Private->WinNtThunk->GetLastError ();\r
+    DEBUG ((EFI_D_ERROR, "SerialSetAttributes: SetCommState %d\n", Private->NtError));\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  //  Set com port read/write timeout values\r
+  //\r
+  ConvertedTime = ConvertTime2Nt (Timeout);\r
+  PortTimeOuts.ReadIntervalTimeout = MAXDWORD;\r
+  PortTimeOuts.ReadTotalTimeoutMultiplier = 0;\r
+  PortTimeOuts.ReadTotalTimeoutConstant = ConvertedTime;\r
+  PortTimeOuts.WriteTotalTimeoutMultiplier = ConvertedTime == 0 ? 1 : ConvertedTime;\r
+  PortTimeOuts.WriteTotalTimeoutConstant = 0;\r
+\r
+  if (!Private->WinNtThunk->SetCommTimeouts (Private->NtHandle, &PortTimeOuts)) {\r
+    Private->NtError = Private->WinNtThunk->GetLastError ();\r
+    DEBUG ((EFI_D_ERROR, "SerialSetAttributes: SetCommTimeouts %d\n", Private->NtError));\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  //  Update mode\r
+  //\r
+  Private->SerialIoMode.BaudRate          = BaudRate;\r
+  Private->SerialIoMode.ReceiveFifoDepth  = ReceiveFifoDepth;\r
+  Private->SerialIoMode.Timeout           = Timeout;\r
+  Private->SerialIoMode.Parity            = Parity;\r
+  Private->SerialIoMode.DataBits          = DataBits;\r
+  Private->SerialIoMode.StopBits          = StopBits;\r
+\r
+  //\r
+  // See if Device Path Node has actually changed\r
+  //\r
+  if (Private->UartDevicePath.BaudRate     == BaudRate &&\r
+      Private->UartDevicePath.DataBits     == DataBits &&\r
+      Private->UartDevicePath.Parity       == Parity   &&\r
+      Private->UartDevicePath.StopBits     == StopBits    ) {\r
+    gBS->RestoreTPL(Tpl);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Update the device path\r
+  //\r
+  Private->UartDevicePath.BaudRate  = BaudRate;\r
+  Private->UartDevicePath.DataBits  = DataBits;\r
+  Private->UartDevicePath.Parity    = (UINT8) Parity;\r
+  Private->UartDevicePath.StopBits  = (UINT8) StopBits;\r
+\r
+  NewDevicePath = AppendDevicePathNode (\r
+                    Private->ParentDevicePath,\r
+                    (EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath\r
+                    );\r
+  if (NewDevicePath == NULL) {\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (Private->Handle != NULL) {\r
+    Status = gBS->ReinstallProtocolInterface (\r
+                    Private->Handle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    Private->DevicePath,\r
+                    NewDevicePath\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->RestoreTPL (Tpl);\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  if (Private->DevicePath != NULL) {\r
+    FreePool (Private->DevicePath);\r
+  }\r
+\r
+  Private->DevicePath = NewDevicePath;\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoSetControl (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This,\r
+  IN UINT32                 Control\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Control - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  WIN_NT_SERIAL_IO_PRIVATE_DATA *Private;\r
+  BOOL                          Result;\r
+  DCB                           Dcb;\r
+  EFI_TPL                       Tpl;\r
+\r
+  Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Result  = Private->WinNtThunk->GetCommState (Private->NtHandle, &Dcb);\r
+\r
+  if (!Result) {\r
+    Private->NtError = Private->WinNtThunk->GetLastError ();\r
+    DEBUG ((EFI_D_ERROR, "SerialSetControl: GetCommState %d\n", Private->NtError));\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  Dcb.fRtsControl                 = RTS_CONTROL_DISABLE;\r
+  Dcb.fDtrControl                 = DTR_CONTROL_DISABLE;\r
+  Private->HardwareFlowControl    = FALSE;\r
+  Private->SoftwareLoopbackEnable = FALSE;\r
+  Private->HardwareLoopbackEnable = FALSE;\r
+\r
+  if (Control & EFI_SERIAL_REQUEST_TO_SEND) {\r
+    Dcb.fRtsControl = RTS_CONTROL_ENABLE;\r
+  }\r
+\r
+  if (Control & EFI_SERIAL_DATA_TERMINAL_READY) {\r
+    Dcb.fDtrControl = DTR_CONTROL_ENABLE;\r
+  }\r
+\r
+  if (Control & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) {\r
+    Private->HardwareFlowControl = TRUE;\r
+  }\r
+\r
+  if (Control & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) {\r
+    Private->SoftwareLoopbackEnable = TRUE;\r
+  }\r
+\r
+  if (Control & EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE) {\r
+    Private->HardwareLoopbackEnable = TRUE;\r
+  }\r
+\r
+  Result = Private->WinNtThunk->SetCommState (\r
+                                  Private->NtHandle,\r
+                                  &Dcb\r
+                                  );\r
+\r
+  if (!Result) {\r
+    Private->NtError = Private->WinNtThunk->GetLastError ();\r
+    DEBUG ((EFI_D_ERROR, "SerialSetControl: SetCommState %d\n", Private->NtError));\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoGetControl (\r
+  IN  EFI_SERIAL_IO_PROTOCOL  *This,\r
+  OUT UINT32                  *Control\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Control - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  WIN_NT_SERIAL_IO_PRIVATE_DATA *Private;\r
+  DWORD                         ModemStatus;\r
+  DWORD                         Errors;\r
+  UINT32                        Bits;\r
+  DCB                           Dcb;\r
+  EFI_TPL                       Tpl;\r
+\r
+  Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  //  Get modem status\r
+  //\r
+  if (!Private->WinNtThunk->GetCommModemStatus (Private->NtHandle, &ModemStatus)) {\r
+    Private->NtError = Private->WinNtThunk->GetLastError ();\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  Bits = 0;\r
+  if (ModemStatus & MS_CTS_ON) {\r
+    Bits |= EFI_SERIAL_CLEAR_TO_SEND;\r
+  }\r
+\r
+  if (ModemStatus & MS_DSR_ON) {\r
+    Bits |= EFI_SERIAL_DATA_SET_READY;\r
+  }\r
+\r
+  if (ModemStatus & MS_RING_ON) {\r
+    Bits |= EFI_SERIAL_RING_INDICATE;\r
+  }\r
+\r
+  if (ModemStatus & MS_RLSD_ON) {\r
+    Bits |= EFI_SERIAL_CARRIER_DETECT;\r
+  }\r
+\r
+  //\r
+  // Get ctrl status\r
+  //\r
+  if (!Private->WinNtThunk->GetCommState (Private->NtHandle, &Dcb)) {\r
+    Private->NtError = Private->WinNtThunk->GetLastError ();\r
+    DEBUG ((EFI_D_ERROR, "SerialGetControl: GetCommState %d\n", Private->NtError));\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (Dcb.fDtrControl == DTR_CONTROL_ENABLE) {\r
+    Bits |= EFI_SERIAL_DATA_TERMINAL_READY;\r
+  }\r
+\r
+  if (Dcb.fRtsControl == RTS_CONTROL_ENABLE) {\r
+    Bits |= EFI_SERIAL_REQUEST_TO_SEND;\r
+  }\r
+\r
+  if (Private->HardwareFlowControl) {\r
+    Bits |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;\r
+  }\r
+\r
+  if (Private->SoftwareLoopbackEnable) {\r
+    Bits |= EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE;\r
+  }\r
+\r
+  if (Private->HardwareLoopbackEnable) {\r
+    Bits |= EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE;\r
+  }\r
+\r
+  //\r
+  //  Get input buffer status\r
+  //\r
+  if (!Private->WinNtThunk->ClearCommError (Private->NtHandle, &Errors, &Private->NtComStatus)) {\r
+    Private->NtError = Private->WinNtThunk->GetLastError ();\r
+    DEBUG ((EFI_D_ERROR, "SerialGetControl: ClearCommError %d\n", Private->NtError));\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (Private->NtComStatus.cbInQue == 0) {\r
+    Bits |= EFI_SERIAL_INPUT_BUFFER_EMPTY;\r
+  }\r
+\r
+  *Control = Bits;\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoWrite (\r
+  IN EFI_SERIAL_IO_PROTOCOL   *This,\r
+  IN OUT UINTN                *BufferSize,\r
+  IN VOID                     *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  WIN_NT_SERIAL_IO_PRIVATE_DATA *Private;\r
+  UINT8                         *ByteBuffer;\r
+  UINTN                         TotalBytesWritten;\r
+  DWORD                         BytesToGo;\r
+  DWORD                         BytesWritten;\r
+  BOOL                          Result;\r
+  UINT32                        Index;\r
+  UINT32                        Control;\r
+  EFI_TPL                       Tpl;\r
+\r
+  Tpl               = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private           = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  ByteBuffer        = (UINT8 *) Buffer;\r
+  TotalBytesWritten = 0;\r
+\r
+  if (Private->SoftwareLoopbackEnable || Private->HardwareLoopbackEnable) {\r
+    for (Index = 0; Index < *BufferSize; Index++) {\r
+      if (IsaSerialFifoAdd (&Private->Fifo, ByteBuffer[Index]) == EFI_SUCCESS) {\r
+        TotalBytesWritten++;\r
+      } else {\r
+        break;\r
+      }\r
+    }\r
+  } else {\r
+    BytesToGo = (DWORD) (*BufferSize);\r
+\r
+    do {\r
+      if (Private->HardwareFlowControl) {\r
+        //\r
+        // Send RTS\r
+        //\r
+        WinNtSerialIoGetControl (&Private->SerialIo, &Control);\r
+        Control |= EFI_SERIAL_REQUEST_TO_SEND;\r
+        WinNtSerialIoSetControl (&Private->SerialIo, Control);\r
+      }\r
+\r
+      //\r
+      //  Do the write\r
+      //\r
+      Result = Private->WinNtThunk->WriteFile (\r
+                                      Private->NtHandle,\r
+                                      &ByteBuffer[TotalBytesWritten],\r
+                                      BytesToGo,\r
+                                      &BytesWritten,\r
+                                      NULL\r
+                                      );\r
+\r
+      if (Private->HardwareFlowControl) {\r
+        //\r
+        // Assert RTS\r
+        //\r
+        WinNtSerialIoGetControl (&Private->SerialIo, &Control);\r
+        Control &= ~ (UINT32) EFI_SERIAL_REQUEST_TO_SEND;\r
+        WinNtSerialIoSetControl (&Private->SerialIo, Control);\r
+      }\r
+\r
+      TotalBytesWritten += BytesWritten;\r
+      BytesToGo -= BytesWritten;\r
+      if (!Result) {\r
+        Private->NtError = Private->WinNtThunk->GetLastError ();\r
+        DEBUG ((EFI_D_ERROR, "SerialWrite: FileWrite %d\n", Private->NtError));\r
+        *BufferSize = TotalBytesWritten;\r
+        gBS->RestoreTPL (Tpl);\r
+        return EFI_DEVICE_ERROR;\r
+      }\r
+    } while (BytesToGo > 0);\r
+  }\r
+\r
+  *BufferSize = TotalBytesWritten;\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoRead (\r
+  IN  EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN  OUT UINTN               *BufferSize,\r
+  OUT VOID                    *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  WIN_NT_SERIAL_IO_PRIVATE_DATA *Private;\r
+  BOOL                          Result;\r
+  DWORD                         BytesRead;\r
+  EFI_STATUS                    Status;\r
+  UINT32                        Index;\r
+  UINT8                         Data;\r
+  UINT32                        Control;\r
+  EFI_TPL                       Tpl;\r
+\r
+  Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  //  Do the read\r
+  //\r
+  if (Private->SoftwareLoopbackEnable || Private->HardwareLoopbackEnable) {\r
+    for (Index = 0, BytesRead = 0; Index < *BufferSize; Index++) {\r
+      if (IsaSerialFifoRemove (&Private->Fifo, &Data) == EFI_SUCCESS) {\r
+        ((UINT8 *) Buffer)[Index] = Data;\r
+        BytesRead++;\r
+      } else {\r
+        break;\r
+      }\r
+    }\r
+  } else {\r
+    if (Private->HardwareFlowControl) {\r
+      WinNtSerialIoGetControl (&Private->SerialIo, &Control);\r
+      Control |= EFI_SERIAL_DATA_TERMINAL_READY;\r
+      WinNtSerialIoSetControl (&Private->SerialIo, Control);\r
+    }\r
+\r
+    Result = Private->WinNtThunk->ReadFile (\r
+                                    Private->NtHandle,\r
+                                    Buffer,\r
+                                    (DWORD) *BufferSize,\r
+                                    &BytesRead,\r
+                                    NULL\r
+                                    );\r
+\r
+    if (Private->HardwareFlowControl) {\r
+      WinNtSerialIoGetControl (&Private->SerialIo, &Control);\r
+      Control &= ~ (UINT32) EFI_SERIAL_DATA_TERMINAL_READY;\r
+      WinNtSerialIoSetControl (&Private->SerialIo, Control);\r
+    }\r
+\r
+    if (!Result) {\r
+      Private->NtError = Private->WinNtThunk->GetLastError ();\r
+      gBS->RestoreTPL (Tpl);\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+  }\r
+\r
+  if (BytesRead != *BufferSize) {\r
+    Status = EFI_TIMEOUT;\r
+  } else {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+  *BufferSize = (UINTN) BytesRead;\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return Status;\r
+}\r
+\r
+BOOLEAN\r
+IsaSerialFifoFull (\r
+  IN SERIAL_DEV_FIFO *Fifo\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  Detect whether specific FIFO is full or not\r
+\r
+  Arguments:\r
+  Fifo  SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO\r
+\r
+  Returns:\r
+  TRUE:  the FIFO is full\r
+  FALSE: the FIFO is not full\r
+\r
+--*/\r
+{\r
+  if (Fifo->Surplus == 0) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+BOOLEAN\r
+IsaSerialFifoEmpty (\r
+  IN SERIAL_DEV_FIFO *Fifo\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  Detect whether specific FIFO is empty or not\r
+\r
+  Arguments:\r
+    Fifo  SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO\r
+\r
+  Returns:\r
+    TRUE:  the FIFO is empty\r
+    FALSE: the FIFO is not empty\r
+\r
+--*/\r
+{\r
+  if (Fifo->Surplus == SERIAL_MAX_BUFFER_SIZE) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+EFI_STATUS\r
+IsaSerialFifoAdd (\r
+  IN SERIAL_DEV_FIFO *Fifo,\r
+  IN UINT8           Data\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  Add data to specific FIFO\r
+\r
+  Arguments:\r
+    Fifo  SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO\r
+    Data  UINT8: the data added to FIFO\r
+\r
+  Returns:\r
+    EFI_SUCCESS:  Add data to specific FIFO successfully\r
+    EFI_OUT_RESOURCE: Failed to add data because FIFO is already full\r
+\r
+--*/\r
+// TODO:    EFI_OUT_OF_RESOURCES - add return value to function comment\r
+{\r
+  //\r
+  // if FIFO full can not add data\r
+  //\r
+  if (IsaSerialFifoFull (Fifo)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // FIFO is not full can add data\r
+  //\r
+  Fifo->Data[Fifo->Last] = Data;\r
+  Fifo->Surplus--;\r
+  Fifo->Last++;\r
+  if (Fifo->Last >= SERIAL_MAX_BUFFER_SIZE) {\r
+    Fifo->Last = 0;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+IsaSerialFifoRemove (\r
+  IN  SERIAL_DEV_FIFO *Fifo,\r
+  OUT UINT8           *Data\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  Remove data from specific FIFO\r
+\r
+  Arguments:\r
+    Fifo  SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO\r
+    Data  UINT8*: the data removed from FIFO\r
+\r
+  Returns:\r
+    EFI_SUCCESS:  Remove data from specific FIFO successfully\r
+    EFI_OUT_RESOURCE: Failed to remove data because FIFO is empty\r
+\r
+--*/\r
+// TODO:    EFI_OUT_OF_RESOURCES - add return value to function comment\r
+{\r
+  //\r
+  // if FIFO is empty, no data can remove\r
+  //\r
+  if (IsaSerialFifoEmpty (Fifo)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // FIFO is not empty, can remove data\r
+  //\r
+  *Data = Fifo->Data[Fifo->First];\r
+  Fifo->Surplus++;\r
+  Fifo->First++;\r
+  if (Fifo->First >= SERIAL_MAX_BUFFER_SIZE) {\r
+    Fifo->First = 0;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.h b/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.h
new file mode 100644 (file)
index 0000000..c53d2e3
--- /dev/null
@@ -0,0 +1,512 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  WinNtSerialIo.h\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#ifndef _WIN_NT_SERIAL_IO_\r
+#define _WIN_NT_SERIAL_IO_\r
+\r
+\r
+#define SERIAL_MAX_BUFFER_SIZE  256\r
+#define TIMEOUT_STALL_INTERVAL  10\r
+\r
+typedef struct {\r
+  UINT32  First;\r
+  UINT32  Last;\r
+  UINT32  Surplus;\r
+  UINT8   Data[SERIAL_MAX_BUFFER_SIZE];\r
+} SERIAL_DEV_FIFO;\r
+\r
+#define WIN_NT_SERIAL_IO_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('N', 'T', 's', 'i')\r
+typedef struct {\r
+  UINT64                    Signature;\r
+\r
+  //\r
+  // Protocol data for the new handle we are going to add\r
+  //\r
+  EFI_HANDLE                Handle;\r
+  EFI_SERIAL_IO_PROTOCOL    SerialIo;\r
+  EFI_SERIAL_IO_MODE        SerialIoMode;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+\r
+  //\r
+  // Private Data\r
+  //\r
+  EFI_HANDLE                ControllerHandle;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  UART_DEVICE_PATH          UartDevicePath;\r
+  EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
+\r
+  EFI_UNICODE_STRING_TABLE  *ControllerNameTable;\r
+\r
+  //\r
+  // Private NT type Data;\r
+  //\r
+  HANDLE                    NtHandle;\r
+  DCB                       NtDCB;\r
+  DWORD                     NtError;\r
+  COMSTAT                   NtComStatus;\r
+\r
+  BOOLEAN                   SoftwareLoopbackEnable;\r
+  BOOLEAN                   HardwareFlowControl;\r
+  BOOLEAN                   HardwareLoopbackEnable;\r
+\r
+  SERIAL_DEV_FIFO           Fifo;\r
+\r
+} WIN_NT_SERIAL_IO_PRIVATE_DATA;\r
+\r
+#define WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, WIN_NT_SERIAL_IO_PRIVATE_DATA, SerialIo, WIN_NT_SERIAL_IO_PRIVATE_DATA_SIGNATURE)\r
+\r
+//\r
+// Global Protocol Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gWinNtSerialIoDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gWinNtSerialIoComponentName;\r
+\r
+//\r
+// Macros to convert EFI serial types to NT serial types.\r
+//\r
+\r
+//\r
+// one second\r
+//\r
+#define SERIAL_TIMEOUT_DEFAULT  (1000 * 1000) \r
+#define SERIAL_BAUD_DEFAULT     115200\r
+#define SERIAL_FIFO_DEFAULT     14\r
+#define SERIAL_DATABITS_DEFAULT 8\r
+#define SERIAL_PARITY_DEFAULT   DefaultParity\r
+#define SERIAL_STOPBITS_DEFAULT DefaultStopBits\r
+\r
+#define SERIAL_CONTROL_MASK     (EFI_SERIAL_CLEAR_TO_SEND       | \\r
+                                 EFI_SERIAL_DATA_SET_READY      | \\r
+                                 EFI_SERIAL_RING_INDICATE       | \\r
+                                 EFI_SERIAL_CARRIER_DETECT      | \\r
+                                 EFI_SERIAL_REQUEST_TO_SEND     | \\r
+                                 EFI_SERIAL_DATA_TERMINAL_READY | \\r
+                                 EFI_SERIAL_INPUT_BUFFER_EMPTY)\r
+\r
+#define ConvertBaud2Nt(x)       (DWORD) x\r
+#define ConvertData2Nt(x)       (BYTE) x\r
+\r
+#define ConvertParity2Nt(x)              \\r
+    (BYTE) (                             \\r
+    x == DefaultParity ? NOPARITY    :   \\r
+    x == NoParity      ? NOPARITY    :   \\r
+    x == EvenParity    ? EVENPARITY  :   \\r
+    x == OddParity     ? ODDPARITY   :   \\r
+    x == MarkParity    ? MARKPARITY  :   \\r
+    x == SpaceParity   ? SPACEPARITY : 0 \\r
+    )\r
+\r
+#define ConvertStop2Nt(x)                 \\r
+    (BYTE) (                                \\r
+    x == DefaultParity   ? ONESTOPBIT   :   \\r
+    x == OneFiveStopBits ? ONE5STOPBITS :   \\r
+    x == TwoStopBits     ? TWOSTOPBITS  : 0 \\r
+    )\r
+\r
+#define ConvertTime2Nt(x) ((x) / 1000)\r
+\r
+//\r
+// 115400 baud with rounding errors\r
+//\r
+#define SERIAL_PORT_MAX_BAUD_RATE 115400  \r
+\r
+//\r
+// Function Prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeWinNtSerialIo (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ImageHandle - TODO: add argument description\r
+  SystemTable - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoDriverBindingSupported (\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
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                - TODO: add argument description\r
+  Handle              - TODO: add argument description\r
+  RemainingDevicePath - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoDriverBindingStart (\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
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                - TODO: add argument description\r
+  Handle              - TODO: add argument description\r
+  RemainingDevicePath - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  UINTN                         NumberOfChildren,\r
+  IN  EFI_HANDLE                    *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  Handle            - TODO: add argument description\r
+  NumberOfChildren  - TODO: add argument description\r
+  ChildHandleBuffer - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoReset (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoSetAttributes (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This,\r
+  IN UINT64                 BaudRate,\r
+  IN UINT32                 ReceiveFifoDepth,\r
+  IN UINT32                 Timeout,\r
+  IN EFI_PARITY_TYPE        Parity,\r
+  IN UINT8                  DataBits,\r
+  IN EFI_STOP_BITS_TYPE     StopBits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  BaudRate          - TODO: add argument description\r
+  ReceiveFifoDepth  - TODO: add argument description\r
+  Timeout           - TODO: add argument description\r
+  Parity            - TODO: add argument description\r
+  DataBits          - TODO: add argument description\r
+  StopBits          - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoSetControl (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This,\r
+  IN UINT32                 Control\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Control - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoGetControl (\r
+  IN  EFI_SERIAL_IO_PROTOCOL  *This,\r
+  OUT UINT32                  *Control\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Control - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoWrite (\r
+  IN EFI_SERIAL_IO_PROTOCOL   *This,\r
+  IN OUT UINTN                *BufferSize,\r
+  IN VOID                     *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSerialIoRead (\r
+  IN  EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN  OUT UINTN               *BufferSize,\r
+  OUT VOID                    *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+BOOLEAN\r
+IsaSerialFifoFull (\r
+  IN SERIAL_DEV_FIFO *Fifo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Fifo  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+BOOLEAN\r
+IsaSerialFifoEmpty (\r
+  IN SERIAL_DEV_FIFO *Fifo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Fifo  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+IsaSerialFifoAdd (\r
+  IN SERIAL_DEV_FIFO *Fifo,\r
+  IN UINT8           Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Fifo  - TODO: add argument description\r
+  Data  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+IsaSerialFifoRemove (\r
+  IN  SERIAL_DEV_FIFO *Fifo,\r
+  OUT UINT8           *Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Fifo  - TODO: add argument description\r
+  Data  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+IsaSerialReceiveTransmit (\r
+  WIN_NT_SERIAL_IO_PRIVATE_DATA     *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
diff --git a/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.inf b/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.inf
new file mode 100644 (file)
index 0000000..59bcf64
--- /dev/null
@@ -0,0 +1,115 @@
+#/** @file\r
+# Serial I/O driver\r
+#\r
+# Our DriverBinding member functions operate on the handles\r
+#  created by the NT Bus drive\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  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
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = WinNtSerialIo\r
+  FILE_GUID                      = 6B41B553-A649-11d4-BD02-0080C73C8881\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeWinNtSerialIo\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+#  DRIVER_BINDING                =  gWinNtSerialIoDriverBinding                  \r
+#  COMPONENT_NAME                =  gWinNtSerialIoComponentName                  \r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  ComponentName.c\r
+  WinNtSerialIo.c\r
+  WinNtSerialIo.h\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg/Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  Nt32Pkg/Nt32Pkg.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  MemoryAllocationLib\r
+  DevicePathLib\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Guid C Name Section - list of Guids that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Guids]\r
+  gEfiWinNtSerialPortGuid                       # ALWAYS_CONSUMED\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiSerialIoProtocolGuid                      # PROTOCOL BY_START\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+  gEfiWinNtIoProtocolGuid                       # PROTOCOL TO_START\r
+\r
diff --git a/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.msa b/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.msa
new file mode 100644 (file)
index 0000000..b7e5107
--- /dev/null
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>WinNtSerialIo</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>6B41B553-A649-11d4-BD02-0080C73C8881</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Serial I/O driver</Abstract>\r
+    <Description>Our DriverBinding member functions operate on the handles\r
+      created by the NT Bus drive</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials\r
+      are licensed and made available under the terms and conditions of the BSD License\r
+      which accompanies this distribution.  The full text of the license may be found at\r
+      http://opensource.org/licenses/bsd-license.php\r
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>WinNtSerialIo</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DevicePathLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>WinNtSerialIo.h</Filename>\r
+    <Filename>WinNtSerialIo.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiWinNtIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiSerialIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiWinNtSerialPortGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gWinNtSerialIoDriverBinding</DriverBinding>\r
+      <ComponentName>gWinNtSerialIoComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file