]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/RtMemoryStatusCode/RtMemoryStatusCode.c
Add in more library for ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Platform / Generic / RuntimeDxe / StatusCode / Lib / RtMemoryStatusCode / RtMemoryStatusCode.c
diff --git a/EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/RtMemoryStatusCode/RtMemoryStatusCode.c b/EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/RtMemoryStatusCode/RtMemoryStatusCode.c
new file mode 100644 (file)
index 0000000..28b5af5
--- /dev/null
@@ -0,0 +1,203 @@
+/*++\r
+\r
+Copyright (c) 2004 - 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
+  RtMemoryStatusCode.c\r
+   \r
+Abstract:\r
+\r
+  EFI lib to provide memory journal status code reporting routines.\r
+\r
+--*/\r
+\r
+#include "RtMemoryStatusCode.h"\r
+\r
+//\r
+// Global variables\r
+//\r
+PEI_STATUS_CODE_MEMORY_PPI  mStatusCodeMemoryPpi = { 0, 0, 0, 0 };\r
+\r
+//\r
+// Function implementations\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+RtMemoryReportStatusCode (\r
+  IN EFI_STATUS_CODE_TYPE     CodeType,\r
+  IN EFI_STATUS_CODE_VALUE    Value,\r
+  IN UINT32                   Instance,\r
+  IN EFI_GUID                 * CallerId,\r
+  IN EFI_STATUS_CODE_DATA     * Data OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Log a status code to a memory journal.  If no memory journal exists, \r
+  we will just return.\r
+\r
+Arguments:\r
+\r
+  Same as ReportStatusCode AP\r
+    \r
+Returns:\r
+\r
+  EFI_SUCCESS   This function always returns success\r
+\r
+--*/\r
+{\r
+  EFI_STATUS_CODE_ENTRY *CurrentEntry;\r
+  UINTN                 MaxEntry;\r
+\r
+  //\r
+  // We don't care to log debug codes.\r
+  //\r
+  if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // Update the latest entry in the journal.\r
+  //\r
+  MaxEntry = mStatusCodeMemoryPpi.Length / sizeof (EFI_STATUS_CODE_ENTRY);\r
+  if (!MaxEntry) {\r
+    //\r
+    // If we don't have any entries, then we can return.\r
+    // This effectively means that no memory buffer was passed forward from PEI.\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  CurrentEntry = (EFI_STATUS_CODE_ENTRY *) (UINTN) (mStatusCodeMemoryPpi.Address + (mStatusCodeMemoryPpi.LastEntry * sizeof (EFI_STATUS_CODE_ENTRY)));\r
+\r
+  mStatusCodeMemoryPpi.LastEntry = (mStatusCodeMemoryPpi.LastEntry + 1) % MaxEntry;\r
+  if (mStatusCodeMemoryPpi.LastEntry == mStatusCodeMemoryPpi.FirstEntry) {\r
+    mStatusCodeMemoryPpi.FirstEntry = (mStatusCodeMemoryPpi.FirstEntry + 1) % MaxEntry;\r
+  }\r
+\r
+  CurrentEntry->Type      = CodeType;\r
+  CurrentEntry->Value     = Value;\r
+  CurrentEntry->Instance  = Instance;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+RtMemoryInitializeStatusCode (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initialization routine.\r
+  Allocates heap space for storing Status Codes.\r
+  Installs a PPI to point to that heap space.\r
+  Installs a callback to switch to memory.\r
+  Installs a callback to \r
+\r
+Arguments: \r
+\r
+  (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
+\r
+Returns: \r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  VOID                        *HobList;\r
+  PEI_STATUS_CODE_MEMORY_PPI  **StatusCodeMemoryPpi;\r
+\r
+  //\r
+  // Locate the HOB that contains the PPI structure for the memory journal\r
+  // We don't check for more than one.\r
+  //\r
+  EfiLibGetSystemConfigurationTable (\r
+    &gEfiHobListGuid,\r
+    &HobList\r
+    );\r
+  Status = GetNextGuidHob (\r
+            &HobList,\r
+            &gPeiStatusCodeMemoryPpiGuid,\r
+            (VOID **) &StatusCodeMemoryPpi,\r
+            NULL\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return ;\r
+  }\r
+  //\r
+  // Copy data to our structure since the HOB will go away at runtime\r
+  //\r
+  // BUGBUG: Virtualize for RT\r
+  //\r
+  mStatusCodeMemoryPpi.FirstEntry = (*StatusCodeMemoryPpi)->FirstEntry;\r
+  mStatusCodeMemoryPpi.LastEntry  = (*StatusCodeMemoryPpi)->LastEntry;\r
+  mStatusCodeMemoryPpi.Address    = (*StatusCodeMemoryPpi)->Address;\r
+  mStatusCodeMemoryPpi.Length     = (*StatusCodeMemoryPpi)->Length;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+PlaybackStatusCodes (\r
+  IN EFI_REPORT_STATUS_CODE   ReportStatusCode\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Call the input ReportStatusCode function with every status code recorded in\r
+  the journal.\r
+\r
+Arguments: \r
+\r
+  ReportStatusCode    ReportStatusCode function to call.\r
+\r
+Returns: \r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN                 MaxEntry;\r
+  EFI_STATUS_CODE_ENTRY *CurrentEntry;\r
+  UINTN                 Counter;\r
+\r
+  if (ReportStatusCode == RtMemoryReportStatusCode) {\r
+    return ;\r
+  }\r
+  //\r
+  // Playback prior status codes to current listeners\r
+  //\r
+  MaxEntry = mStatusCodeMemoryPpi.Length / sizeof (EFI_STATUS_CODE_ENTRY);\r
+  for (Counter = mStatusCodeMemoryPpi.FirstEntry; Counter != mStatusCodeMemoryPpi.LastEntry; Counter++) {\r
+    //\r
+    // Check if we have to roll back to beginning of queue buffer\r
+    //\r
+    if (Counter == MaxEntry) {\r
+      Counter = 0;\r
+    }\r
+    //\r
+    // Play current entry\r
+    //\r
+    CurrentEntry = (EFI_STATUS_CODE_ENTRY *) (UINTN) (mStatusCodeMemoryPpi.Address + (Counter * sizeof (EFI_STATUS_CODE_ENTRY)));\r
+    ReportStatusCode (\r
+      CurrentEntry->Type,\r
+      CurrentEntry->Value,\r
+      CurrentEntry->Instance,\r
+      NULL,\r
+      NULL\r
+      );\r
+  }\r
+}\r