]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/WinNtGopDxe/WinNtGopDriver.c
Add WinNtGop driver into Nt32Pkg
[mirror_edk2.git] / Nt32Pkg / WinNtGopDxe / WinNtGopDriver.c
diff --git a/Nt32Pkg/WinNtGopDxe/WinNtGopDriver.c b/Nt32Pkg/WinNtGopDxe/WinNtGopDriver.c
new file mode 100644 (file)
index 0000000..86b6d19
--- /dev/null
@@ -0,0 +1,378 @@
+/** @file\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
+  WinNtGopDriver.c\r
+\r
+Abstract:\r
+\r
+  This file implements the UEFI Device Driver model requirements for GOP\r
+\r
+  GOP is short hand for Graphics Output Protocol.\r
+\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 <Guid/EventGroup.h>\r
+#include <Protocol/WinNtIo.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Protocol/DriverBinding.h>\r
+#include <Protocol/GraphicsOutput.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/MemoryAllocationLib.h>\r
+\r
+#include "WinNtGop.h"\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gWinNtGopDriverBinding = {\r
+  WinNtGopDriverBindingSupported,\r
+  WinNtGopDriverBindingStart,\r
+  WinNtGopDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+/**\r
+  The user Entry Point for module WinNtGop. 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
+InitializeWinNtGop(\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
+             &gWinNtGopDriverBinding,\r
+             ImageHandle,\r
+             &gWinNtGopComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+\r
+\r
+  @return 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
+EFI_STATUS\r
+EFIAPI\r
+WinNtGopDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_WIN_NT_IO_PROTOCOL  *WinNtIo;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\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)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = WinNtGopSupported (WinNtIo);\r
+\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
+\r
+/**\r
+\r
+\r
+  @return 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_UNSUPPORTED - add return value to function comment\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtGopDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_WIN_NT_IO_PROTOCOL  *WinNtIo;\r
+  EFI_STATUS              Status;\r
+  GOP_PRIVATE_DATA        *Private;\r
+\r
+  //\r
+  // Grab the protocols we need\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)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Allocate Private context data for SGO inteface.\r
+  //\r
+  Private = NULL;\r
+  Private = AllocatePool (sizeof (GOP_PRIVATE_DATA));\r
+  if (Private == NULL) {\r
+    goto Done;\r
+  }\r
+  //\r
+  // Set up context record\r
+  //\r
+  Private->Signature            = GOP_PRIVATE_DATA_SIGNATURE;\r
+  Private->Handle               = Handle;\r
+  Private->WinNtThunk           = WinNtIo->WinNtThunk;\r
+\r
+  Private->ControllerNameTable  = NULL;\r
+\r
+  AddUnicodeString (\r
+    "eng",\r
+    gWinNtGopComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    WinNtIo->EnvString\r
+    );\r
+\r
+  Private->WindowName = WinNtIo->EnvString;\r
+\r
+  Status              = WinNtGopConstructor (Private);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+  //\r
+  // Publish the Gop interface to the world\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Private->Handle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  &Private->GraphicsOutput,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &Private->SimpleTextIn,\r
+                  NULL\r
+                  );\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEfiWinNtIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+\r
+    if (Private != NULL) {\r
+      //\r
+      // On Error Free back private data\r
+      //\r
+      if (Private->ControllerNameTable != NULL) {\r
+        FreeUnicodeStringTable (Private->ControllerNameTable);\r
+      }\r
+\r
+      FreePool (Private);\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+\r
+\r
+  @return 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:    NumberOfChildren - add argument and description to function comment\r
+// TODO:    ChildHandleBuffer - add argument and description to function comment\r
+// TODO:    EFI_NOT_STARTED - add return value to function comment\r
+// TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtGopDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
+  EFI_STATUS                   Status;\r
+  GOP_PRIVATE_DATA             *Private;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  &GraphicsOutput,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // If the GOP interface does not exist the driver is not started\r
+    //\r
+    return EFI_NOT_STARTED;\r
+  }\r
+\r
+  //\r
+  // Get our private context information\r
+  //\r
+  Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);\r
+\r
+  //\r
+  // Remove the SGO interface from the system\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Private->Handle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  &Private->GraphicsOutput,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &Private->SimpleTextIn,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Shutdown the hardware\r
+    //\r
+    Status = WinNtGopDestructor (Private);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEfiWinNtIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+\r
+    //\r
+    // Free our instance data\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+    FreePool (Private);\r
+\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Convert a unicode string to a UINTN\r
+\r
+  @param  String  Unicode string.\r
+\r
+  @return UINTN of the number represented by String.\r
+\r
+**/\r
+UINTN\r
+Atoi (\r
+  CHAR16  *String\r
+  )\r
+{\r
+  UINTN   Number;\r
+  CHAR16  *Str;\r
+\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  Str = String;\r
+  while ((*Str) && (*Str == ' ' || *Str == '"')) {\r
+    Str++;\r
+  }\r
+\r
+  //\r
+  // Convert ot a Number\r
+  //\r
+  Number = 0;\r
+  while (*Str != '\0') {\r
+    if ((*Str >= '0') && (*Str <= '9')) {\r
+      Number = (Number * 10) +*Str - '0';\r
+    } else {\r
+      break;\r
+    }\r
+\r
+    Str++;\r
+  }\r
+\r
+  return Number;\r
+}\r