]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/DebugSupportDxe/DebugSupport.c
Add DebugPort & DebugSupport drivers
[mirror_edk2.git] / MdeModulePkg / Universal / DebugSupportDxe / DebugSupport.c
diff --git a/MdeModulePkg/Universal/DebugSupportDxe/DebugSupport.c b/MdeModulePkg/Universal/DebugSupportDxe/DebugSupport.c
new file mode 100644 (file)
index 0000000..a0ec6c5
--- /dev/null
@@ -0,0 +1,151 @@
+/*++\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
+    DebugSupport.c\r
+\r
+Abstract:\r
+\r
+    Top level C file for debug support driver.  Contains initialization function.\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+//\r
+// private header files\r
+//\r
+#include "plDebugSupport.h"\r
+\r
+//\r
+// This is a global that is the actual interface\r
+//\r
+EFI_DEBUG_SUPPORT_PROTOCOL  gDebugSupportProtocolInterface = {\r
+  EFI_ISA,\r
+  GetMaximumProcessorIndex,\r
+  RegisterPeriodicCallback,\r
+  RegisterExceptionCallback,\r
+  InvalidateInstructionCache\r
+};\r
+\r
+//\r
+// Driver Entry Point\r
+//\r
+EFI_STATUS\r
+InitializeDebugSupportDriver (\r
+  IN EFI_HANDLE               ImageHandle,\r
+  IN EFI_SYSTEM_TABLE         *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Driver entry point.  Checks to see there's not already a DebugSupport protocol\r
+  installed for the selected processor before installing protocol.\r
+\r
+Arguments:\r
+  IN EFI_HANDLE               ImageHandle,\r
+  IN EFI_SYSTEM_TABLE         *SystemTable\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+\r
+--*/\r
+// TODO:    ImageHandle - add argument and description to function comment\r
+// TODO:    SystemTable - add argument and description to function comment\r
+{\r
+  EFI_LOADED_IMAGE_PROTOCOL   *LoadedImageProtocolPtr;\r
+  EFI_STATUS                  Status;\r
+  EFI_HANDLE                  Handle;\r
+  EFI_HANDLE                  *HandlePtr;\r
+  UINTN                       NumHandles;\r
+  EFI_DEBUG_SUPPORT_PROTOCOL  *DebugSupportProtocolPtr;\r
+\r
+  //\r
+  //  Install Protocol Interface...\r
+  //\r
+  // First check to see that the debug support protocol for this processor\r
+  // type is not already installed\r
+  //\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gEfiDebugSupportProtocolGuid,\r
+                  NULL,\r
+                  &NumHandles,\r
+                  &HandlePtr\r
+                  );\r
+\r
+  if (Status != EFI_NOT_FOUND) {\r
+    do {\r
+      NumHandles--;\r
+      Status = gBS->OpenProtocol (\r
+                      HandlePtr[NumHandles],\r
+                      &gEfiDebugSupportProtocolGuid,\r
+                      (VOID **) &DebugSupportProtocolPtr,\r
+                      ImageHandle,\r
+                      NULL,\r
+                      EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                      );\r
+      if (Status == EFI_SUCCESS && DebugSupportProtocolPtr->Isa == EFI_ISA) {\r
+        FreePool (HandlePtr);\r
+        Status = EFI_ALREADY_STARTED;\r
+        goto ErrExit;\r
+      }\r
+    } while (NumHandles > 0);\r
+    FreePool (HandlePtr);\r
+  }\r
+\r
+  //\r
+  // Get our image information and install platform specific unload handler\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ImageHandle,\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  (VOID **) &LoadedImageProtocolPtr,\r
+                  ImageHandle,\r
+                  NULL,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  ASSERT (!EFI_ERROR (Status));\r
+  if (Status != EFI_SUCCESS) {\r
+    goto ErrExit;\r
+  }\r
+\r
+  LoadedImageProtocolPtr->Unload = plUnloadDebugSupportDriver;\r
+\r
+  //\r
+  // Call hook for platform specific initialization\r
+  //\r
+  Status = plInitializeDebugSupportDriver ();\r
+  ASSERT (!EFI_ERROR (Status));\r
+  if (Status != EFI_SUCCESS) {\r
+    goto ErrExit;\r
+  }\r
+\r
+  //\r
+  // Install DebugSupport protocol to new handle\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gEfiDebugSupportProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &gDebugSupportProtocolInterface\r
+                  );\r
+  ASSERT (!EFI_ERROR (Status));\r
+  if (Status != EFI_SUCCESS) {\r
+    goto ErrExit;\r
+  }\r
+\r
+ErrExit:\r
+  return Status;\r
+}\r