]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeProtocolNotify.c
index 5c9a5b8e8972c99cebde1bf3c055f0ff7d30f9ba..de129c26ba181eb2e275793bc49e2d66d970cf73 100644 (file)
@@ -1,7 +1,10 @@
-/*++\r
+/** @file\r
+  This file deals with Architecture Protocol (AP) registration in\r
+  the Dxe Core. The mArchProtocols[] array represents a list of\r
+  events that represent the Architectural Protocols.\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -9,20 +12,9 @@ http://opensource.org/licenses/bsd-license.php
 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
-  DxeProtocolNotify.c\r
-\r
-Abstract:\r
-\r
-  This file deals with Architecture Protocol (AP) registration in\r
-  the Dxe Core. The mArchProtocols[] array represents a list of\r
-  events that represent the Architectural Protocols.\r
-\r
---*/\r
-\r
-#include <DxeMain.h>\r
+**/\r
 \r
+#include "DxeMain.h"\r
 \r
 //\r
 // DXE Core Global Variables for all of the Architectural Protocols.\r
@@ -32,8 +24,7 @@ Abstract:
 // and mArchProtocols[].Registration as it creates events for every array\r
 // entry.\r
 //\r
-\r
-ARCHITECTURAL_PROTOCOL_ENTRY  mArchProtocols[] = {\r
+EFI_CORE_PROTOCOL_NOTIFY_ENTRY  mArchProtocols[] = {\r
   { &gEfiSecurityArchProtocolGuid,         (VOID **)&gSecurity,      NULL, NULL, FALSE },\r
   { &gEfiCpuArchProtocolGuid,              (VOID **)&gCpu,           NULL, NULL, FALSE },\r
   { &gEfiMetronomeArchProtocolGuid,        (VOID **)&gMetronome,     NULL, NULL, FALSE },\r
@@ -43,183 +34,197 @@ ARCHITECTURAL_PROTOCOL_ENTRY  mArchProtocols[] = {
   { &gEfiRuntimeArchProtocolGuid,          (VOID **)&gRuntime,       NULL, NULL, FALSE },\r
   { &gEfiVariableArchProtocolGuid,         (VOID **)NULL,            NULL, NULL, FALSE },\r
   { &gEfiVariableWriteArchProtocolGuid,    (VOID **)NULL,            NULL, NULL, FALSE },\r
-  { &gEfiCapsuleArchProtocolGuid,          (VOID **)NULL,            NULL, NULL, FALSE},\r
+  { &gEfiCapsuleArchProtocolGuid,          (VOID **)NULL,            NULL, NULL, FALSE },\r
   { &gEfiMonotonicCounterArchProtocolGuid, (VOID **)NULL,            NULL, NULL, FALSE },\r
   { &gEfiResetArchProtocolGuid,            (VOID **)NULL,            NULL, NULL, FALSE },\r
   { &gEfiRealTimeClockArchProtocolGuid,    (VOID **)NULL,            NULL, NULL, FALSE },\r
   { NULL,                                  (VOID **)NULL,            NULL, NULL, FALSE }\r
 };\r
 \r
+//\r
+// Optional protocols that the DXE Core will use if they are present\r
+//\r
+EFI_CORE_PROTOCOL_NOTIFY_ENTRY  mOptionalProtocols[] = {\r
+  { &gEfiSmmBase2ProtocolGuid,             (VOID **)&gSmmBase2,      NULL, NULL, FALSE },\r
+  { NULL,                                  (VOID **)NULL,            NULL, NULL, FALSE }\r
+};\r
 \r
-EFI_STATUS\r
-CoreAllEfiServicesAvailable (\r
-  VOID\r
-  )\r
-/*++\r
+//\r
+// Following is needed to display missing architectural protocols in debug builds\r
+//\r
+typedef struct {\r
+  EFI_GUID  *ProtocolGuid;\r
+  CHAR8     *GuidString;\r
+} GUID_TO_STRING_PROTOCOL_ENTRY;\r
 \r
-Routine Description:\r
-  Return TRUE if all AP services are availible.\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY mMissingProtocols[] = {\r
+  { &gEfiSecurityArchProtocolGuid,         "Security"           },\r
+  { &gEfiCpuArchProtocolGuid,              "CPU"                },\r
+  { &gEfiMetronomeArchProtocolGuid,        "Metronome"          },\r
+  { &gEfiTimerArchProtocolGuid,            "Timer"              },\r
+  { &gEfiBdsArchProtocolGuid,              "Bds"                },\r
+  { &gEfiWatchdogTimerArchProtocolGuid,    "Watchdog Timer"     },\r
+  { &gEfiRuntimeArchProtocolGuid,          "Runtime"            },\r
+  { &gEfiVariableArchProtocolGuid,         "Variable"           },\r
+  { &gEfiVariableWriteArchProtocolGuid,    "Variable Write"     },\r
+  { &gEfiCapsuleArchProtocolGuid,          "Capsule"            },\r
+  { &gEfiMonotonicCounterArchProtocolGuid, "Monotonic Counter"  },\r
+  { &gEfiResetArchProtocolGuid,            "Reset"              },\r
+  { &gEfiRealTimeClockArchProtocolGuid,    "Real Time Clock"    },\r
+  { NULL,                                  ""                   }\r
+};\r
 \r
-Arguments:\r
-  NONE\r
+/**\r
+  Return TRUE if all AP services are availible.\r
 \r
-Returns:\r
-  EFI_SUCCESS   - All AP services are available\r
-  EFI_NOT_FOUND - At least one AP service is not available\r
+  @retval EFI_SUCCESS    All AP services are available\r
+  @retval EFI_NOT_FOUND  At least one AP service is not available\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+CoreAllEfiServicesAvailable (\r
+  VOID\r
+  )\r
 {\r
-  ARCHITECTURAL_PROTOCOL_ENTRY  *Entry;\r
+  EFI_CORE_PROTOCOL_NOTIFY_ENTRY  *Entry;\r
 \r
   for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
     if (!Entry->Present) {\r
       return EFI_NOT_FOUND;\r
     }\r
   }\r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
-VOID\r
-EFIAPI\r
-GenericArchProtocolNotify (\r
-  IN   EFI_EVENT       Event,\r
-  IN   VOID            *Context\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
+/**\r
   Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().\r
   This notify function is registered for every architectural protocol. This handler\r
   updates mArchProtocol[] array entry with protocol instance data and sets it's\r
   present flag to TRUE. If any constructor is required it is executed. The EFI\r
   System Table headers are updated.\r
 \r
-Arguments:\r
-\r
-  Event   - The Event that is being processed, not used.\r
-\r
-  Context - Event Context, not used.\r
-\r
-Returns:\r
+  @param  Event          The Event that is being processed, not used.\r
+  @param  Context        Event Context, not used.\r
 \r
-  None\r
-\r
---*/\r
+**/\r
+VOID\r
+EFIAPI\r
+GenericProtocolNotify (\r
+  IN  EFI_EVENT  Event,\r
+  IN  VOID       *Context\r
+  )\r
 {\r
   EFI_STATUS                      Status;\r
-  ARCHITECTURAL_PROTOCOL_ENTRY    *Entry;\r
+  EFI_CORE_PROTOCOL_NOTIFY_ENTRY  *Entry;\r
   VOID                            *Protocol;\r
-  BOOLEAN                         Found;\r
   LIST_ENTRY                      *Link;\r
   LIST_ENTRY                      TempLinkNode;\r
 \r
-  Found = FALSE;\r
-  for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
+  //\r
+  // Get Entry from Context\r
+  //\r
+  Entry = (EFI_CORE_PROTOCOL_NOTIFY_ENTRY *)Context;\r
 \r
-    Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);\r
-    if (EFI_ERROR (Status)) {\r
-      continue;\r
-    }\r
+  //\r
+  // See if the expected protocol is present in the handle database\r
+  //\r
+  Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);\r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
 \r
-    Found = TRUE;\r
-    Entry->Present = TRUE;\r
+  //\r
+  // Mark the protocol as present\r
+  //\r
+  Entry->Present = TRUE;\r
 \r
+  //\r
+  // Update protocol global variable if one exists. Entry->Protocol points to a global variable\r
+  // if one exists in the DXE core for this Architectural Protocol\r
+  //\r
+  if (Entry->Protocol != NULL) {\r
+    *(Entry->Protocol) = Protocol;\r
+  }\r
+\r
+  //\r
+  // Do special operations for Architectural Protocols\r
+  //\r
+\r
+  if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {\r
     //\r
-    // Update protocol global variable if one exists. Entry->Protocol points to a global variable\r
-    // if one exists in the DXE core for this Architectural Protocol\r
+    // Register the Core timer tick handler with the Timer AP\r
     //\r
-    if (Entry->Protocol != NULL) {\r
-      *(Entry->Protocol) = Protocol;\r
-    }\r
+    gTimer->RegisterHandler (gTimer, CoreTimerTick);\r
+  }\r
 \r
-    if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {\r
-      //\r
-      // Register the Core timer tick handler with the Timer AP\r
-      //\r
-      gTimer->RegisterHandler (gTimer, CoreTimerTick);\r
-    }\r
+  if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {\r
+    //\r
+    // When runtime architectural protocol is available, updates CRC32 in the Debug Table\r
+    //\r
+    CoreUpdateDebugTableCrc32 ();\r
 \r
-    if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {\r
-      //\r
-      // When runtime architectural protocol is available, updates CRC32 in the Debug Table\r
-      //\r
-      CoreUpdateDebugTableCrc32 ();\r
-\r
-      //\r
-      // Update the Runtime Architectural protocol with the template that the core was\r
-      // using so there would not need to be a dependency on the Runtime AP\r
-      //\r
-\r
-      //\r
-      // Copy all the registered Image to new gRuntime protocol\r
-      //\r
-      for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {\r
-        CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
-        InsertTailList (&gRuntime->ImageHead, Link);\r
-      }\r
-      //\r
-      // Copy all the registered Event to new gRuntime protocol\r
-      //\r
-      for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {\r
-        CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
-        InsertTailList (&gRuntime->EventHead, Link);\r
-      }\r
+    //\r
+    // Update the Runtime Architectural protocol with the template that the core was\r
+    // using so there would not need to be a dependency on the Runtime AP\r
+    //\r
 \r
-      //\r
-      // Clean up gRuntimeTemplate\r
-      //\r
-      gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;\r
-      gRuntimeTemplate.ImageHead.BackLink    = &gRuntimeTemplate.ImageHead;\r
-      gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;\r
-      gRuntimeTemplate.EventHead.BackLink    = &gRuntimeTemplate.EventHead;\r
+    //\r
+    // Copy all the registered Image to new gRuntime protocol\r
+    //\r
+    for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {\r
+      CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
+      InsertTailList (&gRuntime->ImageHead, Link);\r
     }\r
+    //\r
+    // Copy all the registered Event to new gRuntime protocol\r
+    //\r
+    for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {\r
+      CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
+      InsertTailList (&gRuntime->EventHead, Link);\r
+    }\r
+\r
+    //\r
+    // Clean up gRuntimeTemplate\r
+    //\r
+    gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;\r
+    gRuntimeTemplate.ImageHead.BackLink    = &gRuntimeTemplate.ImageHead;\r
+    gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;\r
+    gRuntimeTemplate.EventHead.BackLink    = &gRuntimeTemplate.EventHead;\r
   }\r
 \r
   //\r
   // It's over kill to do them all every time, but it saves a lot of code.\r
   //\r
-  if (Found) {\r
-    CalculateEfiHdrCrc (&gDxeCoreRT->Hdr);\r
-    CalculateEfiHdrCrc (&gDxeCoreBS->Hdr);\r
-    CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
-    CalculateEfiHdrCrc (&gDxeCoreDS->Hdr);\r
-  }\r
+  CalculateEfiHdrCrc (&gDxeCoreRT->Hdr);\r
+  CalculateEfiHdrCrc (&gBS->Hdr);\r
+  CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
+  CalculateEfiHdrCrc (&gDxeCoreDS->Hdr);\r
 }\r
 \r
+/**\r
+  Creates an event for each entry in a table that is fired everytime a Protocol \r
+  of a specific type is installed.\r
 \r
+  @param Entry  Pointer to EFI_CORE_PROTOCOL_NOTIFY_ENTRY.\r
 \r
+**/\r
 VOID\r
-CoreNotifyOnArchProtocolInstallation (\r
-  VOID\r
+CoreNotifyOnProtocolEntryTable (\r
+  EFI_CORE_PROTOCOL_NOTIFY_ENTRY  *Entry\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Creates an event that is fired everytime a Protocol of a specific type is installed\r
-\r
-Arguments:\r
-  NONE\r
-\r
-Returns:\r
-  NONE\r
-\r
---*/\r
 {\r
-  EFI_STATUS                      Status;\r
-  ARCHITECTURAL_PROTOCOL_ENTRY    *Entry;\r
-\r
-  for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
+  EFI_STATUS  Status;\r
 \r
+  for (; Entry->ProtocolGuid != NULL; Entry++) {\r
     //\r
     // Create the event\r
     //\r
     Status = CoreCreateEvent (\r
               EVT_NOTIFY_SIGNAL,\r
               TPL_CALLBACK,\r
-              GenericArchProtocolNotify,\r
-              NULL,\r
+              GenericProtocolNotify,\r
+              Entry,\r
               &Entry->Event\r
               );\r
     ASSERT_EFI_ERROR(Status);\r
@@ -233,62 +238,42 @@ Returns:
               &Entry->Registration\r
               );\r
     ASSERT_EFI_ERROR(Status);\r
-\r
   }\r
 }\r
 \r
-//\r
-// Following is needed to display missing architectural protocols in debug builds\r
-//\r
-typedef struct {\r
-  EFI_GUID                    *ProtocolGuid;\r
-  CHAR16                       *GuidString;\r
-} GUID_TO_STRING_PROTOCOL_ENTRY;\r
-\r
-static const GUID_TO_STRING_PROTOCOL_ENTRY MissingProtocols[] = {\r
-  { &gEfiSecurityArchProtocolGuid,         (CHAR16 *)L"Security"           },\r
-  { &gEfiCpuArchProtocolGuid,              (CHAR16 *)L"CPU"                },\r
-  { &gEfiMetronomeArchProtocolGuid,        (CHAR16 *)L"Metronome"          },\r
-  { &gEfiTimerArchProtocolGuid,            (CHAR16 *)L"Timer"              },\r
-  { &gEfiBdsArchProtocolGuid,              (CHAR16 *)L"Bds"                },\r
-  { &gEfiWatchdogTimerArchProtocolGuid,    (CHAR16 *)L"Watchdog Timer"     },\r
-  { &gEfiRuntimeArchProtocolGuid,          (CHAR16 *)L"Runtime"            },\r
-  { &gEfiVariableArchProtocolGuid,         (CHAR16 *)L"Variable"           },\r
-  { &gEfiVariableWriteArchProtocolGuid,    (CHAR16 *)L"Variable Write"     },\r
-  { &gEfiCapsuleArchProtocolGuid,          (CHAR16 *)L"Capsule"            },\r
-  { &gEfiMonotonicCounterArchProtocolGuid, (CHAR16 *)L"Monotonic Counter"  },\r
-  { &gEfiResetArchProtocolGuid,            (CHAR16 *)L"Reset"              },\r
-//  { &gEfiStatusCodeRuntimeProtocolGuid,       (CHAR16 *)L"Status Code"        },\r
-  { &gEfiRealTimeClockArchProtocolGuid,    (CHAR16 *)L"Real Time Clock"    }\r
-};\r
+/**\r
+  Creates an events for the Architectural Protocols and the optional protocols \r
+  that are fired everytime a Protocol of a specific type is installed.\r
 \r
+**/\r
 VOID\r
-CoreDisplayMissingArchProtocols (\r
+CoreNotifyOnProtocolInstallation (\r
   VOID\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Displays Architectural protocols that were not loaded and are required for DXE core to function\r
-  Only used in Debug Builds\r
+{\r
+  CoreNotifyOnProtocolEntryTable (mArchProtocols);\r
+  CoreNotifyOnProtocolEntryTable (mOptionalProtocols);\r
+}\r
 \r
-Arguments:\r
-  NONE\r
 \r
-Returns:\r
-  NONE\r
+/**\r
+  Displays Architectural protocols that were not loaded and are required for DXE\r
+  core to function.  Only used in Debug Builds.\r
 \r
---*/\r
+**/\r
+VOID\r
+CoreDisplayMissingArchProtocols (\r
+  VOID\r
+  )\r
 {\r
-  const GUID_TO_STRING_PROTOCOL_ENTRY  *MissingEntry;\r
-  ARCHITECTURAL_PROTOCOL_ENTRY         *Entry;\r
+  EFI_CORE_PROTOCOL_NOTIFY_ENTRY       *Entry;\r
+  CONST GUID_TO_STRING_PROTOCOL_ENTRY  *MissingEntry;\r
 \r
   for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
     if (!Entry->Present) {\r
-      MissingEntry = MissingProtocols;\r
-      for (MissingEntry = MissingProtocols; TRUE ; MissingEntry++) {\r
+      for (MissingEntry = mMissingProtocols; MissingEntry->ProtocolGuid != NULL; MissingEntry++) {\r
         if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {\r
-          DEBUG ((EFI_D_ERROR, "\n%s Arch Protocol not present!!\n", MissingEntry->GuidString));\r
+          DEBUG ((DEBUG_ERROR, "\n%a Arch Protocol not present!!\n", MissingEntry->GuidString));\r
           break;\r
         }\r
       }\r